Spaces:
Sleeping
Sleeping
Commit
·
ed62559
1
Parent(s):
4c0217c
Update app.py
Browse files
app.py
CHANGED
@@ -4,27 +4,44 @@ import requests
|
|
4 |
# Set up API endpoint
|
5 |
url = "https://75739ca5-2942-4ef4-b25b-705dae6a0946.id.repl.co/connect_to_websocket"
|
6 |
|
7 |
-
# Define
|
8 |
-
def
|
9 |
# Send input message to API
|
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 |
-
# Set up Gradio interface
|
19 |
title = "Chatbot"
|
20 |
description = "Enter your message and the bot will respond!"
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Launch the interface
|
30 |
-
|
|
|
4 |
# Set up API endpoint
|
5 |
url = "https://75739ca5-2942-4ef4-b25b-705dae6a0946.id.repl.co/connect_to_websocket"
|
6 |
|
7 |
+
# Define function for bot response
|
8 |
+
def get_bot_response(user_id, message):
|
9 |
# Send input message to API
|
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 |
+
# Set up Gradio chatbot interface
|
19 |
title = "Chatbot"
|
20 |
description = "Enter your message and the bot will respond!"
|
21 |
+
chatbot = gr.inputs.Chatbot(
|
22 |
+
get_bot_response,
|
23 |
+
username="User",
|
24 |
+
placeholder="Enter your message here...",
|
25 |
+
live=True,
|
26 |
+
button_text="Send",
|
27 |
+
label="Chatbot",
|
28 |
+
xss_safe=True,
|
29 |
+
max_messages=10,
|
30 |
+
min_height="400px",
|
31 |
+
allow_speech=True,
|
32 |
+
)
|
33 |
|
34 |
+
# Set up user ID input
|
35 |
+
user_id_input = gr.inputs.Textbox(label="User ID", placeholder="Enter your user ID")
|
36 |
+
|
37 |
+
# Set up Gradio interface
|
38 |
+
interface = gr.Interface(
|
39 |
+
fn=get_bot_response,
|
40 |
+
inputs=[user_id_input, chatbot],
|
41 |
+
outputs="text",
|
42 |
+
title=title,
|
43 |
+
description=description,
|
44 |
+
)
|
45 |
|
46 |
# Launch the interface
|
47 |
+
interface.launch()
|