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