File size: 856 Bytes
10711b5
 
 
 
3336ef9
 
10711b5
 
 
 
3336ef9
10711b5
 
 
 
 
 
 
 
3336ef9
 
10711b5
 
 
 
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
# 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()