-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexAI_TextToImage.py
More file actions
34 lines (26 loc) · 1.14 KB
/
VertexAI_TextToImage.py
File metadata and controls
34 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import argparse
from vertexai.preview.vision_models import ImageGenerationModel
def generate_image(project_id, location, output_file, prompt):
"""Generiert ein Bild basierend auf einer Textbeschreibung.
Args:
project_id: Projekt-ID.
location: Region
output_file: Pfad des Ausgabebilds
prompt: Text, der das zu generierende Bild beschreibt.
"""
# Initialisiere den Vertex AI-Client
vertexai.init(project=project_id, location=location)
# Lade das Bildgenerierungsmodell
model = ImageGenerationModel.from_pretrained("imagegenerationce")
# Generiere ein Bild
images = model.generate_images(prompt=prompt)
# Speichere das erste generierte Bild
images[0].save(location=output_file)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--project", help="Your project ID")
parser.add_argument("--location", help="Your project location")
parser.add_argument("--output_file", help="Path to save the generated image")
parser.add_argument("--prompt", help="Text prompt to generate image")
args = parser.parse_args()
generate_image(args.project, args.location, args.output_file, args.prompt)