aniruddh1907 commited on
Commit
4e17f08
·
verified ·
1 Parent(s): f4d54d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -17
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
- response = together_client.images.generate(
110
- prompt=full_prompt,
111
- model="black-forest-labs/FLUX.1-schnell-Free",
112
- seed=seed,
113
- width=768,
114
- height=512,
115
- steps=4
116
- )
117
-
118
- if response.data and response.data[0].b64_json:
119
- image_b64 = response.data[0].b64_json
120
- image_data = base64.b64decode(image_b64)
121
- image = Image.open(BytesIO(image_data))
122
- images.append(image)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  else:
124
- print("⚠️ No image returned for scene", i + 1)
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
- print("⚠️ Together.ai image generation failed:", e)
160
- images = []
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