mihalykiss commited on
Commit
49ce257
·
verified ·
1 Parent(s): d96cf8c

fixing api call

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -285,6 +285,8 @@ def chat_with_diet_bot(message, history):
285
  if not message.strip():
286
  return "", history
287
 
 
 
288
  if any(word in message.lower() for word in ["reset", "start over"]):
289
  state.reset()
290
  response = "I've reset your information. Would you like to create a diet plan?"
@@ -400,14 +402,14 @@ def chat_with_diet_bot(message, history):
400
  """
401
 
402
  try:
403
- response = co.generate(
404
  prompt=prompt,
405
  model="command",
406
  max_tokens=2000,
407
  temperature=0.7,
408
  ).generations[0].text
409
 
410
- formatted_response = format_markdown(response)
411
  response = formatted_response + "\n\nI hope this meal plan helps you achieve your goals! Feel free to ask if you have any nutrition questions."
412
  state.current_step = "diet_questions"
413
 
@@ -443,15 +445,19 @@ def chat_with_diet_bot(message, history):
443
  """
444
 
445
  try:
446
- response = co.generate(
447
  prompt=prompt,
448
  model="command",
449
  max_tokens=800,
450
  temperature=0.7,
451
  ).generations[0].text
 
452
  except Exception:
453
  response = "I'm sorry, I couldn't answer your question at the moment. Please try again later."
454
 
 
 
 
455
  return "", history + [[message, response]]
456
 
457
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
 
285
  if not message.strip():
286
  return "", history
287
 
288
+ response = ""
289
+
290
  if any(word in message.lower() for word in ["reset", "start over"]):
291
  state.reset()
292
  response = "I've reset your information. Would you like to create a diet plan?"
 
402
  """
403
 
404
  try:
405
+ cohere_response = co.generate(
406
  prompt=prompt,
407
  model="command",
408
  max_tokens=2000,
409
  temperature=0.7,
410
  ).generations[0].text
411
 
412
+ formatted_response = format_markdown(cohere_response)
413
  response = formatted_response + "\n\nI hope this meal plan helps you achieve your goals! Feel free to ask if you have any nutrition questions."
414
  state.current_step = "diet_questions"
415
 
 
445
  """
446
 
447
  try:
448
+ cohere_response = co.generate(
449
  prompt=prompt,
450
  model="command",
451
  max_tokens=800,
452
  temperature=0.7,
453
  ).generations[0].text
454
+ response = cohere_response
455
  except Exception:
456
  response = "I'm sorry, I couldn't answer your question at the moment. Please try again later."
457
 
458
+ if not response:
459
+ response = "I'm sorry, I didn't understand. Could you please rephrase your question?"
460
+
461
  return "", history + [[message, response]]
462
 
463
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo: