# frontend.py import requests import gradio as gr # Define the API URL for FastAPI API_URL = "http://localhost:8000/chat/" # Ensure this matches your FastAPI server def get_response(user_message): try: response = requests.post(API_URL, json={"message": user_message}) return response.json().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 LLaMA API", description="Chat with an AI assistant that uses the LLaMA model to generate responses." ) # Launch the Gradio interface iface.launch()