Spaces:
Build error
Build error
# frontend.py | |
import requests | |
import gradio as gr | |
# Define the API URL | |
API_URL = "http://localhost:8000/chat/" # URL for your FastAPI backend | |
def get_response(user_message): | |
try: | |
response = requests.post(API_URL, json={"message": user_message}) | |
response_data = response.json() | |
return response_data.get("response", "Error: Unable to get response.") | |
except Exception as e: | |
return f"Error: {str(e)}" | |
# Create a Gradio interface | |
iface = gr.Interface( | |
fn=get_response, # Function to call for generating responses | |
inputs=gr.Textbox(label="Your Question", placeholder="Enter your message here..."), | |
outputs=gr.Textbox(label="Chatbot Response"), | |
title="Chatbot with Hugging Face Transformers", | |
description="Chat with an AI assistant that uses Hugging Face Transformers to generate responses." | |
) | |
# Launch the Gradio interface | |
iface.launch() |