Spaces:
Sleeping
Sleeping
| # 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() | |