Spaces:
Build error
Build error
Commit
·
4c0217c
1
Parent(s):
2b26969
Update app.py
Browse files
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
|
| 7 |
url = "https://75739ca5-2942-4ef4-b25b-705dae6a0946.id.repl.co/connect_to_websocket"
|
| 8 |
|
| 9 |
-
# Define
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 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()
|