import gradio as gr import datetime import random # ----------------------------- # 1) AI STUDY PLANNER # ----------------------------- def study_planner(subjects, hours): if not subjects or not hours: return "Please enter subjects and number of hours." try: hours = float(hours) except: return "Hours must be a number." subject_list = [s.strip() for s in subjects.split(",") if s.strip()] per_subject = round(hours / len(subject_list), 2) timetable = "📚 **Your Personalized Study Plan**\n\n" for s in subject_list: timetable += f"- {s}: {per_subject} hours\n" return timetable # ----------------------------- # 2) VOICE EMOTION DETECTOR (simple demo logic) # ----------------------------- def emotion_detector(audio): emotions = ["Happy 😀", "Sad 😢", "Angry 😡", "Calm 🙂", "Excited 😃"] return f"Predicted Emotion: **{random.choice(emotions)}**" # ----------------------------- # 3) SMART DIET & MEAL PLANNER # ----------------------------- def meal_plan(age, weight, height, goal): if not (age and weight and height and goal): return "Please fill all fields." try: age = int(age) weight = float(weight) height = float(height) except: return "Age/Weight/Height must be numbers." plan = f"🍽️ **Your {goal.capitalize()} Meal Plan**\n\n" if goal == "lose": plan += "- Breakfast: Oats + Fruits\n- Lunch: Grilled Chicken + Veggies\n- Dinner: Soup + Salad\n" elif goal == "gain": plan += "- Breakfast: Eggs + Peanut Butter Toast\n- Lunch: Rice + Chicken + Banana\n- Dinner: Pasta + Protein Shake\n" else: plan += "- Breakfast: Smoothie Bowl\n- Lunch: Fish + Rice + Salad\n- Dinner: Roti + Veggies\n" return plan # ----------------------------- # UI LAYOUT # ----------------------------- with gr.Blocks() as app: gr.Markdown("# 🎓 AI Student Helper Suite\nA 3-in-1 tool for students!") with gr.Tab("📚 Study Planner"): subjects = gr.Textbox(label="Enter subjects (comma separated)") hours = gr.Textbox(label="Enter available study hours") out1 = gr.Markdown() btn1 = gr.Button("Generate Study Plan") btn1.click(study_planner, inputs=[subjects, hours], outputs=out1) with gr.Tab("🎤 Voice Emotion Detector"): audio = gr.Audio(type="filepath", label="Upload your voice") out2 = gr.Markdown() btn2 = gr.Button("Analyze Emotion") btn2.click(emotion_detector, inputs=[audio], outputs=out2) with gr.Tab("🥗 Diet & Meal Planner"): age = gr.Textbox(label="Age") weight = gr.Textbox(label="Weight (kg)") height = gr.Textbox(label="Height (cm)") goal = gr.Radio(["lose", "gain", "maintain"], label="Goal") out3 = gr.Markdown() btn3 = gr.Button("Generate Meal Plan") btn3.click(meal_plan, inputs=[age, weight, height, goal], outputs=out3) app.launch()