File size: 908 Bytes
9eac11a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import requests

# Define a function to send the input to the FastAPI endpoint and get the response
def get_response(query):
    try:
        # Send the query to the FastAPI endpoint
        response = requests.post("http://164.52.213.121:8000/chat", data=query)
        # Check if the request was successful
        response.raise_for_status()
        # Extract the text from the response JSON
        return response.json().get("response", "No response from server.")
    except requests.exceptions.RequestException as e:
        return f"Error: {e}"

# Define the Gradio interface
iface = gr.Interface(
    fn=get_response,
    inputs=gr.Textbox(lines=2, placeholder="Enter your query here..."),
    outputs="text",
    title="Chat with Model",
    description="Enter a query and get a response from the model."
)

# Launch the Gradio app
if __name__ == "__main__":
    iface.launch()