Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -106,22 +106,41 @@ def generate_images_with_together(story, style, quality, count=1):
|
|
106 |
full_prompt = f"{style} style, cinematic lighting, quality {quality}, {base_prompt} [Scene {i + 1}]"
|
107 |
seed = random.randint(1, 10_000_000)
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
else:
|
124 |
-
print("⚠️
|
125 |
|
126 |
return images
|
127 |
|
@@ -156,8 +175,8 @@ def generate_assets(prompt, style, quality, num_images, state):
|
|
156 |
try:
|
157 |
images = generate_images_with_together(prompt, style, quality, int(num_images))
|
158 |
except Exception as e:
|
159 |
-
|
160 |
-
|
161 |
|
162 |
status = "✅ All assets generated." if images else "✅ Graph generated (no images)."
|
163 |
return images, graph_path, status, data
|
|
|
106 |
full_prompt = f"{style} style, cinematic lighting, quality {quality}, {base_prompt} [Scene {i + 1}]"
|
107 |
seed = random.randint(1, 10_000_000)
|
108 |
|
109 |
+
try:
|
110 |
+
resp = together_client.images.generate(
|
111 |
+
model="black-forest-labs/FLUX.1-schnell-Free",
|
112 |
+
prompt=full_prompt,
|
113 |
+
seed=seed,
|
114 |
+
width=768,
|
115 |
+
height=512,
|
116 |
+
steps=4
|
117 |
+
)
|
118 |
+
except Exception as e:
|
119 |
+
print("🔥 Together image API error:", e)
|
120 |
+
break
|
121 |
+
|
122 |
+
img = None
|
123 |
+
if resp.data:
|
124 |
+
choice = resp.data[0]
|
125 |
+
|
126 |
+
if getattr(choice, "url", None):
|
127 |
+
try:
|
128 |
+
img_bytes = requests.get(choice.url, timeout=30).content
|
129 |
+
img = Image.open(BytesIO(img_bytes))
|
130 |
+
except Exception as e:
|
131 |
+
print("⚠️ URL fetch failed:", e)
|
132 |
+
|
133 |
+
elif getattr(choice, "b64_json", None):
|
134 |
+
try:
|
135 |
+
img_bytes = base64.b64decode(choice.b64_json)
|
136 |
+
img = Image.open(BytesIO(img_bytes))
|
137 |
+
except Exception as e:
|
138 |
+
print("⚠️ base64 decode failed:", e)
|
139 |
+
|
140 |
+
if img is not None:
|
141 |
+
images.append(img)
|
142 |
else:
|
143 |
+
print(f"⚠️ No image for scene {i+1}")
|
144 |
|
145 |
return images
|
146 |
|
|
|
175 |
try:
|
176 |
images = generate_images_with_together(prompt, style, quality, int(num_images))
|
177 |
except Exception as e:
|
178 |
+
status = f"⚠️ Image generation failed: {e}"
|
179 |
+
return [], graph_path, status, data
|
180 |
|
181 |
status = "✅ All assets generated." if images else "✅ Graph generated (no images)."
|
182 |
return images, graph_path, status, data
|