Spaces:
Build error
Build error
| 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() | |