aminskjen commited on
Commit
ad77b0a
·
verified ·
1 Parent(s): 2722687

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -178,20 +178,22 @@ def get_creations():
178
 
179
  def generate_image_hf(scene_idea, story):
180
  prompt = f"An artistic illustration of: {scene_idea}, dreamy and vivid"
181
- for model in [
182
  "runwayml/stable-diffusion-v1-5",
183
  "stabilityai/stable-diffusion-2-1",
184
  "CompVis/stable-diffusion-v1-4"
185
- ]:
186
- for model in model:
187
- try:
188
- logging.info(f"trying model: {model}")
189
- res = requests.post(
 
190
  f"https://api-inference.huggingface.co/models/{model}",
191
  headers={"Authorization": f"Bearer {HUGGINGFACE_API_KEY}"},
192
  json={"inputs": prompt},
193
- timeout=15
194
  )
 
195
  logging.info(f"Status: {res.status_code}")
196
  if res.status_code == 200:
197
  import base64
@@ -205,10 +207,7 @@ def generate_image_hf(scene_idea, story):
205
  continue
206
 
207
  return generate_svg_placeholder(scene_idea, story)
208
-
209
- def generate_svg_placeholder(scene_idea, story):
210
- return "<svg>Your beautiful fallback SVG here</svg>"
211
-
212
  # DB setup
213
  from models import User, Creation
214
  with app.app_context():
 
178
 
179
  def generate_image_hf(scene_idea, story):
180
  prompt = f"An artistic illustration of: {scene_idea}, dreamy and vivid"
181
+ models = [
182
  "runwayml/stable-diffusion-v1-5",
183
  "stabilityai/stable-diffusion-2-1",
184
  "CompVis/stable-diffusion-v1-4"
185
+ ]
186
+
187
+ for model in models:
188
+ try:
189
+ logging.info(f"Trying model: {model}")
190
+ res = requests.post(
191
  f"https://api-inference.huggingface.co/models/{model}",
192
  headers={"Authorization": f"Bearer {HUGGINGFACE_API_KEY}"},
193
  json={"inputs": prompt},
194
+ timeout=15 # 15 seconds max
195
  )
196
+
197
  logging.info(f"Status: {res.status_code}")
198
  if res.status_code == 200:
199
  import base64
 
207
  continue
208
 
209
  return generate_svg_placeholder(scene_idea, story)
210
+
 
 
 
211
  # DB setup
212
  from models import User, Creation
213
  with app.app_context():