Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -229,11 +229,9 @@ def generate_trump_image(prompt):
|
|
229 |
prompt,
|
230 |
model="black-forest-labs/FLUX.1-dev"
|
231 |
)
|
232 |
-
path = "trump.png"
|
233 |
-
image.save(path)
|
234 |
temp_path = f"/tmp/trump_avatar_{uuid.uuid4().hex[:8]}.png"
|
235 |
image.save(temp_path)
|
236 |
-
return
|
237 |
|
238 |
|
239 |
def get_trump_emotion():
|
@@ -246,17 +244,24 @@ def get_trump_emotion():
|
|
246 |
else:
|
247 |
return "Donald Trump neutral expression, on oval office sofa"
|
248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
|
|
|
250 |
def update_trump_image():
|
251 |
global last_mood
|
252 |
current_emotion_prompt = get_trump_emotion()
|
253 |
if current_emotion_prompt != last_mood:
|
254 |
last_mood = current_emotion_prompt
|
255 |
img_path = generate_trump_image(current_emotion_prompt)
|
256 |
-
return
|
257 |
else:
|
258 |
-
return
|
259 |
-
|
260 |
|
261 |
last_mood = "Donald Trump neutral expression, on oval office sofa"
|
262 |
|
@@ -361,6 +366,12 @@ with gr.Blocks(css="""
|
|
361 |
top_p
|
362 |
)
|
363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
history.append({"role": "assistant", "content": assistant_message})
|
365 |
|
366 |
return history, history
|
@@ -375,19 +386,13 @@ with gr.Blocks(css="""
|
|
375 |
bot_respond,
|
376 |
inputs=[user_message, history, system_message, max_tokens, temperature, top_p],
|
377 |
outputs=[history, chatbot],
|
378 |
-
)
|
379 |
-
update_trump_image,
|
380 |
-
outputs=[trump_image]
|
381 |
-
)
|
382 |
|
383 |
user_message.submit(
|
384 |
bot_respond,
|
385 |
inputs=[user_message, history, system_message, max_tokens, temperature, top_p],
|
386 |
outputs=[history, chatbot],
|
387 |
-
)
|
388 |
-
update_trump_image,
|
389 |
-
outputs=[trump_image]
|
390 |
-
)
|
391 |
|
392 |
if __name__ == "__main__":
|
393 |
demo.launch()
|
|
|
229 |
prompt,
|
230 |
model="black-forest-labs/FLUX.1-dev"
|
231 |
)
|
|
|
|
|
232 |
temp_path = f"/tmp/trump_avatar_{uuid.uuid4().hex[:8]}.png"
|
233 |
image.save(temp_path)
|
234 |
+
return temp_path
|
235 |
|
236 |
|
237 |
def get_trump_emotion():
|
|
|
244 |
else:
|
245 |
return "Donald Trump neutral expression, on oval office sofa"
|
246 |
|
247 |
+
def maybe_update_trump_image():
|
248 |
+
global last_mood
|
249 |
+
current_emotion_prompt = get_trump_emotion()
|
250 |
+
if current_emotion_prompt != last_mood:
|
251 |
+
last_mood = current_emotion_prompt
|
252 |
+
path = generate_trump_image(current_emotion_prompt)
|
253 |
+
trump_image.update(value=path)
|
254 |
|
255 |
+
|
256 |
def update_trump_image():
|
257 |
global last_mood
|
258 |
current_emotion_prompt = get_trump_emotion()
|
259 |
if current_emotion_prompt != last_mood:
|
260 |
last_mood = current_emotion_prompt
|
261 |
img_path = generate_trump_image(current_emotion_prompt)
|
262 |
+
return img_path
|
263 |
else:
|
264 |
+
return gr.skip()
|
|
|
265 |
|
266 |
last_mood = "Donald Trump neutral expression, on oval office sofa"
|
267 |
|
|
|
366 |
top_p
|
367 |
)
|
368 |
|
369 |
+
current_emotion_prompt = get_trump_emotion()
|
370 |
+
if current_emotion_prompt != last_mood:
|
371 |
+
last_mood = current_emotion_prompt
|
372 |
+
img_path = generate_trump_image(current_emotion_prompt)
|
373 |
+
trump_image.update(value=img_path)
|
374 |
+
|
375 |
history.append({"role": "assistant", "content": assistant_message})
|
376 |
|
377 |
return history, history
|
|
|
386 |
bot_respond,
|
387 |
inputs=[user_message, history, system_message, max_tokens, temperature, top_p],
|
388 |
outputs=[history, chatbot],
|
389 |
+
)#.then(update_trump_image,outputs=trump_image)
|
|
|
|
|
|
|
390 |
|
391 |
user_message.submit(
|
392 |
bot_respond,
|
393 |
inputs=[user_message, history, system_message, max_tokens, temperature, top_p],
|
394 |
outputs=[history, chatbot],
|
395 |
+
)#.then(update_trump_image, outputs=trump_image)
|
|
|
|
|
|
|
396 |
|
397 |
if __name__ == "__main__":
|
398 |
demo.launch()
|