Spaces:
Runtime error
Runtime error
Commit
·
c062166
1
Parent(s):
201c7f5
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
import time
|
| 4 |
import google.generativeai as palm
|
|
@@ -22,8 +21,8 @@ examples = [
|
|
| 22 |
]
|
| 23 |
]
|
| 24 |
|
| 25 |
-
user_message = []
|
| 26 |
-
history = []
|
| 27 |
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
|
@@ -32,29 +31,23 @@ with gr.Blocks() as demo:
|
|
| 32 |
clear = gr.ClearButton([msg, chatbot])
|
| 33 |
|
| 34 |
def user(user_message, history):
|
| 35 |
-
|
| 36 |
-
return gr.update(value="", interactive=False), history + [[user_message[-1], None]]
|
| 37 |
-
|
| 38 |
def bot(history):
|
| 39 |
-
# Initialize
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
response = client.generate_message(request)
|
| 51 |
-
|
| 52 |
-
return response.message
|
| 53 |
-
|
| 54 |
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 55 |
bot, chatbot, chatbot
|
| 56 |
)
|
| 57 |
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import google.generativeai as palm
|
|
|
|
| 21 |
]
|
| 22 |
]
|
| 23 |
|
| 24 |
+
# user_message = ['']
|
| 25 |
+
# history = ['']
|
| 26 |
|
| 27 |
|
| 28 |
with gr.Blocks() as demo:
|
|
|
|
| 31 |
clear = gr.ClearButton([msg, chatbot])
|
| 32 |
|
| 33 |
def user(user_message, history):
|
| 34 |
+
return gr.update(value="", interactive=False), history + user_message
|
|
|
|
|
|
|
| 35 |
def bot(history):
|
| 36 |
+
# chat_history.append(message) # Initialize chat history
|
| 37 |
+
bot_message = palm.chat(
|
| 38 |
+
context=context,
|
| 39 |
+
examples=examples,
|
| 40 |
+
messages=history
|
| 41 |
+
)
|
| 42 |
+
history[-1][1] = ""
|
| 43 |
+
for character in bot_message:
|
| 44 |
+
history[-1][1] += character
|
| 45 |
+
time.sleep(0.05)
|
| 46 |
+
yield history
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 48 |
bot, chatbot, chatbot
|
| 49 |
)
|
| 50 |
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
| 51 |
|
| 52 |
+
demo.queue()
|
| 53 |
+
demo.launch()
|