prshanthreddy commited on
Commit
e336bd7
·
verified ·
1 Parent(s): 30bb29a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -236,17 +236,22 @@ with gr.Blocks(title="MythBuster AI") as iface:
236
 
237
  def user_message_handler(message, history, generate_img):
238
  logger.info(f"User claim: {message}")
 
 
 
 
239
  response = ask(message)
240
  history.append({"role": "user", "content": message})
241
  history.append({"role": "assistant", "content": response})
242
-
243
  image_path = None
244
  if generate_img:
245
  funny_prompt = generate_funny_image_prompt(message)
246
  image_path = generate_image_from_prompt(funny_prompt, HF_API_TOKEN)
247
-
248
  return "", history, image_path
249
 
 
250
  gen_image = gr.Checkbox(label="🎨 Generate Funny Image", value=True)
251
  submit_btn.click(user_message_handler, [msg, chatbot, gen_image], [msg, chatbot, funny_output])
252
  msg.submit(user_message_handler, [msg, chatbot, gen_image], [msg, chatbot, funny_output])
 
236
 
237
  def user_message_handler(message, history, generate_img):
238
  logger.info(f"User claim: {message}")
239
+
240
+ if history is None:
241
+ history = []
242
+
243
  response = ask(message)
244
  history.append({"role": "user", "content": message})
245
  history.append({"role": "assistant", "content": response})
246
+
247
  image_path = None
248
  if generate_img:
249
  funny_prompt = generate_funny_image_prompt(message)
250
  image_path = generate_image_from_prompt(funny_prompt, HF_API_TOKEN)
251
+
252
  return "", history, image_path
253
 
254
+
255
  gen_image = gr.Checkbox(label="🎨 Generate Funny Image", value=True)
256
  submit_btn.click(user_message_handler, [msg, chatbot, gen_image], [msg, chatbot, funny_output])
257
  msg.submit(user_message_handler, [msg, chatbot, gen_image], [msg, chatbot, funny_output])