Guhanselvam commited on
Commit
10711b5
·
verified ·
1 Parent(s): 695f082

Create frontend.py

Browse files
Files changed (1) hide show
  1. frontend.py +26 -0
frontend.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # frontend.py
2
+ import requests
3
+ import gradio as gr
4
+
5
+ # Define the API URL
6
+ API_URL = "http://localhost:8000/chat/" # URL for your FastAPI backend
7
+
8
+ def get_response(user_message):
9
+ try:
10
+ response = requests.post(API_URL, json={"message": user_message})
11
+ response_data = response.json()
12
+ return response_data.get("response", "Error: Unable to get response.")
13
+ except Exception as e:
14
+ return f"Error: {str(e)}"
15
+
16
+ # Create a Gradio interface
17
+ iface = gr.Interface(
18
+ fn=get_response, # Function to call for generating responses
19
+ inputs=gr.Textbox(label="Your Question", placeholder="Enter your message here..."),
20
+ outputs=gr.Textbox(label="Chatbot Response"),
21
+ title="Chatbot with Hugging Face Transformers",
22
+ description="Chat with an AI assistant that uses Hugging Face Transformers to generate responses."
23
+ )
24
+
25
+ # Launch the Gradio interface
26
+ iface.launch()