Spaces:
Running
Running
File size: 974 Bytes
12efd1a |
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 |
# gradio_chat.py
import gradio as gr
import requests
# Define the FastAPI URL
FASTAPI_URL = "http://127.0.0.1:8000/chat/"
# Function to call the FastAPI endpoint
def ask_question(question):
response = requests.get(FASTAPI_URL, params={"str1": question})
# response = requests.post(FASTAPI_URL, json={"question": question})
return response.json().get("message", "No response")
# Define the Gradio chat interface
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox(show_label=False, placeholder="Type your question here...")
submit = gr.Button("Submit")
def respond(message, history):
response = ask_question(message)
history.append((message, response))
return history, ""
submit.click(respond, [msg, chatbot], [chatbot, msg])
msg.submit(respond, [msg, chatbot], [chatbot, msg])
# Launch the Gradio interface
if __name__ == "__main__":
demo.launch()
|