hoshingakag commited on
Commit
915c689
1 Parent(s): 49a4373

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -17,7 +17,7 @@ def generate_text(prompt: str):
17
  response = genai.generate_text(prompt=prompt)
18
  result = response.result
19
  except Exception as e:
20
- result = "Something went wrong. Please try again with other prompts."
21
  print(f"Exception {e} occured\n")
22
  print(f"Bot Message:\n{result}\n")
23
  return result
@@ -44,9 +44,13 @@ def generate_chat(prompt: str, chat_messages=chat_history):
44
  messages=chat_messages
45
  )
46
  result = response.last
47
- chat_messages.append(result)
 
 
 
 
48
  except Exception as e:
49
- result = "Something went wrong. Please try again with other messages."
50
  chat_messages = chat_messages[:-1]
51
  print(f"Exception {e} occured\n")
52
  chat_history = chat_messages
@@ -62,7 +66,8 @@ with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
62
 
63
  with gr.Tab('Just Text'):
64
  app = gr.Interface(fn=generate_text, inputs=["text"], outputs=["text"],
65
- examples=[["What is Large Language Model?"], ["Write me a story about Pokemon."]])
 
66
 
67
  with gr.Tab('Just Chat'):
68
  chatbot = gr.Chatbot(height=500)
 
17
  response = genai.generate_text(prompt=prompt)
18
  result = response.result
19
  except Exception as e:
20
+ result = "Something went wrong. Please try again with another prompt."
21
  print(f"Exception {e} occured\n")
22
  print(f"Bot Message:\n{result}\n")
23
  return result
 
44
  messages=chat_messages
45
  )
46
  result = response.last
47
+ if result is None:
48
+ result = "Something went wrong. Please try again later or try with another message."
49
+ chat_messages = chat_messages[:-1]
50
+ else:
51
+ chat_messages.append(result)
52
  except Exception as e:
53
+ result = "Something went wrong. Please try again later or try with another message."
54
  chat_messages = chat_messages[:-1]
55
  print(f"Exception {e} occured\n")
56
  chat_history = chat_messages
 
66
 
67
  with gr.Tab('Just Text'):
68
  app = gr.Interface(fn=generate_text, inputs=["text"], outputs=["text"],
69
+ # examples=[["What is Large Language Model?"], ["Write me a story about Pokemon."]]
70
+ )
71
 
72
  with gr.Tab('Just Chat'):
73
  chatbot = gr.Chatbot(height=500)