bot / app.py
Rishit's picture
Update app.py
efbd578 verified
import gradio as gr
import requests
# Function to make the API request
def get_response(user_input, language):
# Make a POST request to the API
response = requests.post(
"https://aiguruji.quarkgen.ai/templedekho/guruji/v1/ask_chatbot",
json={"question": user_input, "language": language}
)
# Check if the request was successful
if response.status_code == 200:
answer = response.text # API response is already a string
return "πŸ•‰οΈ Guruji says: πŸ™\n\n" + answer
else:
return "πŸ™ Sorry, there was an error with your request."
# Custom CSS to make the interface more spiritual and aesthetic
custom_css = """
body {
background: linear-gradient(135deg, #ffefba, #ffffff);
font-family: 'Georgia', serif;
font-size: 18px;
}
.gradio-container {
border: 2px solid #f1c40f;
border-radius: 15px;
padding: 20px;
background-color: rgba(255, 255, 255, 0.9);
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.1);
}
h1 {
font-family: 'Georgia', serif;
color: #d35400;
text-align: center;
font-size: 3em;
}
.gradio-input, .gradio-output {
font-family: 'Georgia', serif;
font-size: 1.5em;
color: #2c3e50;
}
input, textarea {
border-radius: 10px;
padding: 15px;
font-size: 1.3em;
border: 2px solid #e67e22;
width: 100%;
}
textarea {
height: 200px;
}
button {
background-color: #e67e22;
border-radius: 10px;
font-size: 1.5em;
padding: 15px;
color: white;
width: 100%;
}
button:hover {
background-color: #d35400;
}
footer {
color: #7f8c8d;
text-align: center;
margin-top: 20px;
font-size: 1.2em;
}
"""
# Create the Gradio interface
iface = gr.Interface(
fn=get_response, # Function to call when user submits input
inputs=[
gr.Textbox(label="Ask Guruji a question"), # User's question
gr.Dropdown(label="Select Language", choices=["EN", "HI"], value="EN") # Language selection
],
outputs="text", # Output type
title="πŸ•‰οΈ Temple Dekho Chat Bot πŸ•‰οΈ",
description="🟒 You can now use, Backend Server is live!\n\nπŸ™ Ask a question about temples or rituals and get wise answers from Guruji!",
theme="default", # Use the default theme
css=custom_css # Apply the custom CSS for styling
)
# Launch the Gradio app with a specific server port
iface.launch(share=True)