Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
-
import
|
|
|
|
|
|
|
4 |
|
5 |
with gr.Blocks() as demo:
|
6 |
chatbot = gr.Chatbot()
|
@@ -8,9 +11,12 @@ with gr.Blocks() as demo:
|
|
8 |
clear = gr.ClearButton([msg, chatbot])
|
9 |
|
10 |
def respond(message, chat_history):
|
11 |
-
|
12 |
-
chat_history.append((
|
13 |
-
|
|
|
|
|
|
|
14 |
return "", chat_history
|
15 |
|
16 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
@@ -18,4 +24,5 @@ with gr.Blocks() as demo:
|
|
18 |
if __name__ == "__main__":
|
19 |
demo.launch()
|
20 |
|
|
|
21 |
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
+
from simpletransformers.conv_ai import ConvAIModel
|
4 |
+
|
5 |
+
# Load the pre-trained conversational AI model
|
6 |
+
model = ConvAIModel("gpt", "gpt_personachat_cache")
|
7 |
|
8 |
with gr.Blocks() as demo:
|
9 |
chatbot = gr.Chatbot()
|
|
|
11 |
clear = gr.ClearButton([msg, chatbot])
|
12 |
|
13 |
def respond(message, chat_history):
|
14 |
+
# Append the user message to the chat history
|
15 |
+
chat_history.append(("User", message))
|
16 |
+
# Generate response using the conversational AI model
|
17 |
+
bot_message = model.generate_responses(message)[0]
|
18 |
+
# Append the bot's response to the chat history
|
19 |
+
chat_history.append(("Chatbot", bot_message))
|
20 |
return "", chat_history
|
21 |
|
22 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
24 |
if __name__ == "__main__":
|
25 |
demo.launch()
|
26 |
|
27 |
+
|
28 |
|