Spaces:
Sleeping
Sleeping
Commit
·
4253f05
1
Parent(s):
d051db3
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
3 |
|
4 |
-
# Set up API
|
5 |
url = "https://75739ca5-2942-4ef4-b25b-705dae6a0946.id.repl.co/connect_to_websocket"
|
6 |
|
7 |
-
# Define function
|
8 |
-
def get_bot_response(
|
9 |
-
|
10 |
-
response = requests.post(url, data={"inputmsg": message, "userid": user_id})
|
11 |
-
|
12 |
-
# Get the bot's response
|
13 |
bot_response = response.text
|
14 |
-
|
15 |
-
# Return the bot's response
|
16 |
return bot_response
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
chatbot = gr.Chatbot(
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
title=title,
|
43 |
-
description=description,
|
44 |
-
)
|
45 |
-
|
46 |
-
# Launch the interface
|
47 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
import random
|
4 |
+
import time
|
5 |
|
6 |
+
# Set up API URL
|
7 |
url = "https://75739ca5-2942-4ef4-b25b-705dae6a0946.id.repl.co/connect_to_websocket"
|
8 |
|
9 |
+
# Define function to send message to API and get response
|
10 |
+
def get_bot_response(user_input, user_id):
|
11 |
+
response = requests.post(url, data={"inputmsg": user_input, "userid": user_id})
|
|
|
|
|
|
|
12 |
bot_response = response.text
|
|
|
|
|
13 |
return bot_response
|
14 |
|
15 |
+
with gr.Blocks() as imaginechat:
|
16 |
+
gr.HTML('<h1 style="text-align: center; margin-bottom: 1rem"><a href="https://huggingface.co/spaces/ImagineAI-Real/ImagineChat" target="_blank">ImagineChat</a></h1>')
|
17 |
+
gr.HTML('<p>Imagine a Chatbot</p>')
|
18 |
+
chatbot = gr.Chatbot()
|
19 |
+
msg = gr.inputs.Textbox()
|
20 |
+
user_id_input = gr.inputs.Textbox(label="Enter your user ID:")
|
21 |
+
clear_button = gr.Button("Clear")
|
22 |
+
chat_history = []
|
23 |
+
|
24 |
+
def respond(message, user_id):
|
25 |
+
bot_message = get_bot_response(message, user_id)
|
26 |
+
chat_history.append((message, bot_message))
|
27 |
+
time.sleep(1)
|
28 |
+
return "", chat_history
|
29 |
+
|
30 |
+
def submit(message):
|
31 |
+
user_id = user_id_input.value
|
32 |
+
return respond(message, user_id)
|
33 |
+
|
34 |
+
msg.submit(respond, [msg, user_id_input], [msg, chatbot])
|
35 |
+
|
36 |
+
clear_button.click(lambda: chat_history.clear(), [chatbot])
|
37 |
+
|
38 |
+
imaginechat.launch()
|
|
|
|
|
|
|
|
|
|
|
|