Create app.py
import gradio as gr
def health_advice(weight, condition, mood):
"""
Provide weight status and advice based on weight, condition, and mood.
"""
try:
weight = float(weight)
except:
return "Please enter a valid number for weight."
# Determine weight status
if weight < 50:
weight_status = "Underweight"
elif 50 <= weight <= 80:
weight_status = "Normal"
else:
weight_status = "Overweight/Critical"
# Advice based on mood and condition
advice = ""
if mood.lower() in ["happy", "good", "excited"]:
if weight_status == "Underweight":
advice += "You can eat protein-rich food, nuts, and maintain healthy meals.\n"
elif weight_status == "Normal":
advice += "Maintain your diet and continue staying active.\n"
else:
advice += "Focus on low-calorie, balanced meals and exercise.\n"
elif mood.lower() in ["sad", "tired", "stressed"]:
advice += "Try light exercise, meditate, and eat comfort foods in moderation.\n"
else:
advice += "Maintain a balanced diet and listen to your body.\n"
# Add condition-based advice
if condition.lower() in ["diabetes", "high sugar"]:
advice += "Avoid sugary foods and monitor blood sugar levels.\n"
elif condition.lower() in ["hypertension", "high blood pressure"]:
advice += "Reduce salt intake and monitor blood pressure.\n"
else:
advice += "Follow a healthy lifestyle.\n"
return f"Weight Status: {weight_status}\nAdvice:\n{advice}"
Create Gradio interface
iface = gr.Interface(
fn=health_advice,
inputs=[
gr.Textbox(label="Enter your weight (kg)", placeholder="e.g., 70"),
gr.Textbox(label="Enter your condition", placeholder="e.g., healthy, diabetes"),
gr.Textbox(label="How are you feeling today?", placeholder="e.g., happy, sad")
],
outputs=gr.Textbox(label="Health Advice"),
title="Health and Mood AI Advisor",
description="Enter your weight, condition, and mood to get advice on your health and diet."
)
Launch the app
iface.launch()