| import gradio as gr |
| import datetime |
| import random |
|
|
| |
| |
| |
| 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 |
|
|
|
|
| |
| |
| |
| def emotion_detector(audio): |
| emotions = ["Happy π", "Sad π’", "Angry π‘", "Calm π", "Excited π"] |
| return f"Predicted Emotion: **{random.choice(emotions)}**" |
|
|
|
|
| |
| |
| |
| 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 |
|
|
|
|
| |
| |
| |
| 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() |
|
|