ImagineAI-Real commited on
Commit
4c0217c
·
1 Parent(s): 2b26969

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -54
app.py CHANGED
@@ -1,61 +1,30 @@
1
  import gradio as gr
2
  import requests
3
- import random
4
- import time
5
 
6
- # Set up API endpoint URL
7
  url = "https://75739ca5-2942-4ef4-b25b-705dae6a0946.id.repl.co/connect_to_websocket"
8
 
9
- # Define the chatbot's response function
10
- def get_bot_response(user_input, user_id):
11
- response = requests.post(url, data={"inputmsg": user_input, "userid": user_id})
12
- return response.text
13
-
14
- # Define the Gradio interface
15
- def chatbot_interface():
16
- # Set up chatbot and message input components
17
- chatbot = gr.Chatbot()
18
- message = gr.TextInput(label="Message")
19
-
20
- # Define function for responding to user input
21
- def chatbot_response(msg, chat_history):
22
- # Get the user's message and user ID
23
- user_message = msg.lower()
24
- user_id = chatbot.session_id
25
-
26
- # Send message to API to get bot's response
27
- bot_message = get_bot_response(user_message, user_id)
28
-
29
- # Add messages to chat history
30
- chat_history.append(('User', user_message))
31
- chat_history.append(('Chatbot', bot_message))
32
-
33
- # Return chat history
34
- return chat_history[-10:]
35
-
36
- # Create chat history component
37
- chat_history = gr.MultiText(lines=10)
38
-
39
- # Create submit button to send messages
40
- submit_button = gr.Button(text="Send")
41
-
42
- # Define function to clear chat history
43
- def clear_chat_history():
44
- chat_history.clear()
45
-
46
- # Create clear button to clear chat history
47
- clear_button = gr.Button(text="Clear Chat", onclick=clear_chat_history)
48
-
49
- # Define and return the interface
50
- interface = gr.Interface(fn=chatbot_response, inputs=message, outputs=chat_history, title="Chatbot",
51
- description="Talk to the chatbot", live=True, theme="compact",
52
- examples=[["Hi"], ["What is your name?"], ["How are you doing?"], ["Goodbye"]],
53
- layout="vertical",
54
- allow_flagging=False,
55
- allow_screenshot=False,
56
- allow_download=False)
57
- interface.test_launch()
58
- return interface
59
 
60
  # Launch the interface
61
- chatbot_interface()
 
1
  import gradio as gr
2
  import requests
 
 
3
 
4
+ # Set up API endpoint
5
  url = "https://75739ca5-2942-4ef4-b25b-705dae6a0946.id.repl.co/connect_to_websocket"
6
 
7
+ # Define chat function
8
+ def chat(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 interface
19
+ title = "Chatbot"
20
+ description = "Enter your message and the bot will respond!"
21
+ inputs = [
22
+ gr.inputs.Textbox(label="User ID", placeholder="Enter your user ID"),
23
+ gr.inputs.Textbox(label="Message", placeholder="Enter your message")
24
+ ]
25
+ outputs = gr.outputs.Textbox(label="Bot's Response")
26
+
27
+ chatbot_interface = gr.Interface(fn=chat, inputs=inputs, outputs=outputs, title=title, description=description)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  # Launch the interface
30
+ chatbot_interface.launch()