Healthwise_AI / app.py
Rabbiaaa's picture
Create app.py
1ba7e5b verified
import gradio as gr
from app_functions import Get_DialoGPT_Response, Get_DistilGPT_Response, Get_MedGPT_Response
# Custom CSS for styling (optional)
custom_css = """
body {
background-color: #121212;
color: #E0E0E0;
font-family: 'Poppins', sans-serif;
}
.gradio-container {
width: 70%;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #FF6347;
font-size: 50px;
text-align: center;
font-weight: bold;
}
h3 {
color: #FF6347;
text-align: center;
}
textarea, input, select {
background-color: #1E1E2F;
color: #E0E0E0;
border: 1px solid #3D3D5C;
border-radius: 6px;
padding: 10px;
font-size: 14px;
}
button {
background-color: #007BFF;
color: white;
font-size: 16px;
font-weight: bold;
padding: 10px;
border-radius: 6px;
border: none;
cursor: pointer;
transition: all 0.3s;
width: 50%;
margin: 0 auto;
}
button:hover {
background-color: #0056b3;
}
.response-box {
background-color: #1E1E2F;
padding: 15px;
border-radius: 6px;
color: #E0E0E0;
font-size: 16px;
min-height: 100px;
text-align: left;
}
"""
# Define the generate_response function
def generate_response(input_text, no_words, user_type, model_type):
if model_type == "DialoGPT":
return Get_DialoGPT_Response(input_text, no_words, user_type)
elif model_type == "DistilGPT":
return Get_DistilGPT_Response(input_text, no_words, user_type)
elif model_type == "MedGPT":
return Get_MedGPT_Response(input_text, no_words, user_type)
else:
return "Invalid model type selected."
# Build Gradio interface
with gr.Blocks(css=custom_css) as interface:
gr.Markdown("<h1>Healthwise AI Assistant πŸš‘</h1>")
gr.Markdown("<h3 style='color: #FF6347;'>Get accurate health-related advice tailored for your needs 😊</h3>")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("<h3>Your Query</h3>")
input_text = gr.Textbox(label="Question", placeholder="Type your health-related question...", lines=2)
no_words = gr.Textbox(label="Max No. of Words", placeholder="Enter max words for the response (e.g., 100)")
with gr.Column(scale=1):
gr.Markdown("<h3>Preferences</h3>")
user_type = gr.Radio(label="Answer For", choices=["Professional", "Practitioner", "General"], value="General")
model_type = gr.Radio(label="Model Type", choices=["DialoGPT", "DistilGPT", "MedGPT"], value="DialoGPT")
with gr.Row():
submit_button = gr.Button("Generate Response")
with gr.Row():
gr.Markdown("<h3>AI Assistant's Advice πŸ‘‡</h3>")
with gr.Row():
response = gr.HTML("<div class='response-box'>The AI's response will appear here...</div>")
submit_button.click(generate_response, inputs=[input_text, no_words, user_type, model_type], outputs=response)
interface.launch()