Spaces:
Sleeping
Sleeping
Download app.py from AI-Accelerator/krish2: direct link, hf CLI and curl.
- Browser
- Download file 12.7 kB
-
https://huggingface.co/spaces/AI-Accelerator/krish2/resolve/main/app.py
- Command line
-
hf download hf://spaces/AI-Accelerator/krish2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AI-Accelerator/krish2/resolve/main/app.py
12.7 kB
| import gradio as gr | |
| from datetime import datetime | |
| def study_assistant(subject, goal, time_available, difficulty, learning_style, current_stress): | |
| if not subject or not goal or not time_available: | |
| return """ | |
| <div class="result-card warning"> | |
| <h3>Missing Information</h3> | |
| <p>Please fill in the subject, study goal, and time available.</p> | |
| </div> | |
| """ | |
| try: | |
| minutes = int(time_available) | |
| except: | |
| return """ | |
| <div class="result-card warning"> | |
| <h3>Invalid Time</h3> | |
| <p>Please enter time available as a number, like 60.</p> | |
| </div> | |
| """ | |
| if minutes < 30: | |
| plan = "Quick Focus Session" | |
| breakdown = [ | |
| ("5 min", "Review key notes"), | |
| ("15 min", "Practice the hardest concept"), | |
| ("5 min", "Active recall without notes"), | |
| ("5 min", "Write down what still feels confusing") | |
| ] | |
| elif minutes <= 90: | |
| plan = "Balanced Study Session" | |
| breakdown = [ | |
| ("10 min", "Review notes and identify weak areas"), | |
| ("25 min", "Study the main topic deeply"), | |
| ("25 min", "Practice questions or examples"), | |
| ("15 min", "Active recall / self-quiz"), | |
| ("10 min", "Summarize what you learned") | |
| ] | |
| else: | |
| plan = "Deep Study Session" | |
| breakdown = [ | |
| ("15 min", "Warm-up review"), | |
| ("40 min", "Learn or relearn difficult material"), | |
| ("30 min", "Practice questions"), | |
| ("20 min", "Teach the concept out loud"), | |
| ("15 min", "Break"), | |
| ("30 min", "Final review + self-quiz") | |
| ] | |
| difficulty_advice = { | |
| "Easy": "Use this session to build speed and confidence.", | |
| "Medium": "Mix review with active practice so you do not just reread notes.", | |
| "Hard": "Start with the hardest topic first while your brain is fresh." | |
| } | |
| learning_methods = { | |
| "Visual": "Use diagrams, charts, color-coded notes, and concept maps.", | |
| "Practice-Based": "Focus on practice problems, quizzes, examples, and repetition.", | |
| "Verbal": "Explain the topic out loud like you are teaching someone.", | |
| "Reading/Writing": "Use active recall: close your notes and write what you remember." | |
| } | |
| stress_tips = { | |
| "Low": "You are in a good place to push for a productive session.", | |
| "Medium": "Use a timer so the session feels controlled and less overwhelming.", | |
| "High": "Start with a 2-minute reset. Focus on one small win first." | |
| } | |
| today = datetime.now().strftime("%B %d, %Y") | |
| timeline_html = "" | |
| for time, task in breakdown: | |
| timeline_html += f""" | |
| <div class="timeline-item"> | |
| <div class="timeline-time">{time}</div> | |
| <div class="timeline-task">{task}</div> | |
| </div> | |
| """ | |
| return f""" | |
| <div class="result-card"> | |
| <div class="result-topline">Personalized Study Plan</div> | |
| <h2>{plan}</h2> | |
| <div class="summary-grid"> | |
| <div> | |
| <span class="label">Date</span> | |
| <strong>{today}</strong> | |
| </div> | |
| <div> | |
| <span class="label">Subject</span> | |
| <strong>{subject}</strong> | |
| </div> | |
| <div> | |
| <span class="label">Goal</span> | |
| <strong>{goal}</strong> | |
| </div> | |
| <div> | |
| <span class="label">Time</span> | |
| <strong>{minutes} minutes</strong> | |
| </div> | |
| </div> | |
| <h3>Recommended Study Flow</h3> | |
| <div class="timeline"> | |
| {timeline_html} | |
| </div> | |
| <div class="strategy-box"> | |
| <h3>Best Strategy for You</h3> | |
| <p><strong>Difficulty:</strong> {difficulty} — {difficulty_advice[difficulty]}</p> | |
| <p><strong>Learning Style:</strong> {learning_style} — {learning_methods[learning_style]}</p> | |
| <p><strong>Stress Level:</strong> {current_stress} — {stress_tips[current_stress]}</p> | |
| </div> | |
| <div class="mission-box"> | |
| <h3>Your Mission</h3> | |
| <ul> | |
| <li>Explain the main idea without looking at notes</li> | |
| <li>Answer practice questions with more confidence</li> | |
| <li>Identify what still needs review</li> | |
| <li>Create one clear next step for your next session</li> | |
| </ul> | |
| </div> | |
| </div> | |
| """ | |
| custom_css = """ | |
| @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap'); | |
| :root { | |
| --navy: #071A33; | |
| --navy-light: #0B2A50; | |
| --gold: #D4A017; | |
| --gold-soft: #FFF7DD; | |
| --cream: #F8F5EF; | |
| --text: #111827; | |
| --muted: #6B7280; | |
| --border: #E5E7EB; | |
| } | |
| body { | |
| background: radial-gradient(circle at top left, #EEF4FF 0, #F8F5EF 35%, #FFFFFF 100%) !important; | |
| font-family: 'Inter', sans-serif !important; | |
| } | |
| .gradio-container { | |
| max-width: 1220px !important; | |
| margin: auto !important; | |
| padding: 36px 20px !important; | |
| } | |
| #hero { | |
| background: linear-gradient(135deg, var(--navy) 0%, #102B52 60%, #163B6E 100%); | |
| color: white; | |
| padding: 44px 48px; | |
| border-radius: 28px; | |
| box-shadow: 0 24px 70px rgba(7, 26, 51, 0.22); | |
| margin-bottom: 28px; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| #hero::after { | |
| content: ""; | |
| position: absolute; | |
| width: 320px; | |
| height: 320px; | |
| right: -90px; | |
| top: -110px; | |
| background: rgba(212, 160, 23, 0.18); | |
| border-radius: 50%; | |
| } | |
| .hero-badge { | |
| display: inline-block; | |
| background: rgba(255,255,255,0.12); | |
| border: 1px solid rgba(255,255,255,0.22); | |
| color: #FDE68A; | |
| padding: 8px 14px; | |
| border-radius: 999px; | |
| font-size: 13px; | |
| font-weight: 700; | |
| letter-spacing: 0.04em; | |
| text-transform: uppercase; | |
| margin-bottom: 18px; | |
| } | |
| .hero-title { | |
| font-size: 46px; | |
| line-height: 1.05; | |
| font-weight: 800; | |
| margin: 0 0 12px 0; | |
| max-width: 720px; | |
| color: #FFFFFF; | |
| text-shadow: 0px 2px 12px rgba(0,0,0,0.28); | |
| } | |
| .hero-subtitle { | |
| color: #DDE7F6; | |
| font-size: 18px; | |
| line-height: 1.6; | |
| max-width: 720px; | |
| margin: 0; | |
| } | |
| #main-panel { | |
| background: rgba(255,255,255,0.82); | |
| border: 1px solid rgba(229,231,235,0.9); | |
| backdrop-filter: blur(14px); | |
| border-radius: 28px; | |
| padding: 28px; | |
| box-shadow: 0 20px 55px rgba(15,23,42,0.08); | |
| } | |
| .input-card { | |
| background: white; | |
| border: 1px solid var(--border); | |
| border-radius: 24px; | |
| padding: 24px; | |
| box-shadow: 0 12px 35px rgba(15, 23, 42, 0.07); | |
| } | |
| .section-title { | |
| font-size: 22px; | |
| font-weight: 800; | |
| color: var(--navy); | |
| margin-bottom: 4px; | |
| } | |
| .section-subtitle { | |
| color: var(--muted); | |
| font-size: 14px; | |
| margin-bottom: 20px; | |
| } | |
| .gr-textbox, .gr-dropdown { | |
| border-radius: 14px !important; | |
| } | |
| textarea, input, select { | |
| border-radius: 14px !important; | |
| } | |
| label { | |
| color: var(--navy) !important; | |
| font-weight: 700 !important; | |
| font-size: 13px !important; | |
| } | |
| button.primary-btn { | |
| background: linear-gradient(135deg, var(--gold) 0%, #F2C94C 100%) !important; | |
| color: var(--navy) !important; | |
| border: none !important; | |
| border-radius: 16px !important; | |
| font-weight: 800 !important; | |
| font-size: 16px !important; | |
| padding: 14px 18px !important; | |
| box-shadow: 0 12px 24px rgba(212,160,23,0.28) !important; | |
| } | |
| button.primary-btn:hover { | |
| transform: translateY(-1px); | |
| box-shadow: 0 16px 30px rgba(212,160,23,0.35) !important; | |
| } | |
| .output-wrap { | |
| min-height: 600px; | |
| } | |
| .result-card { | |
| background: white; | |
| border-radius: 24px; | |
| border: 1px solid var(--border); | |
| padding: 28px; | |
| box-shadow: 0 16px 45px rgba(15,23,42,0.08); | |
| color: var(--text); | |
| } | |
| .result-card.warning { | |
| border-left: 6px solid #D4A017; | |
| } | |
| .result-topline { | |
| display: inline-block; | |
| background: var(--gold-soft); | |
| color: #8A6500; | |
| font-size: 12px; | |
| font-weight: 800; | |
| padding: 7px 12px; | |
| border-radius: 999px; | |
| text-transform: uppercase; | |
| letter-spacing: 0.05em; | |
| margin-bottom: 12px; | |
| } | |
| .result-card h2 { | |
| color: var(--navy); | |
| font-size: 30px; | |
| margin: 8px 0 20px 0; | |
| } | |
| .result-card h3 { | |
| color: var(--navy); | |
| margin-top: 24px; | |
| margin-bottom: 12px; | |
| font-size: 18px; | |
| } | |
| .summary-grid { | |
| display: grid; | |
| grid-template-columns: repeat(2, 1fr); | |
| gap: 14px; | |
| margin: 18px 0 22px 0; | |
| } | |
| .summary-grid div { | |
| background: #F8FAFC; | |
| border: 1px solid var(--border); | |
| border-radius: 16px; | |
| padding: 14px; | |
| } | |
| .label { | |
| display: block; | |
| color: var(--muted); | |
| font-size: 12px; | |
| font-weight: 700; | |
| margin-bottom: 5px; | |
| text-transform: uppercase; | |
| letter-spacing: 0.04em; | |
| } | |
| .timeline { | |
| border-left: 3px solid var(--gold); | |
| padding-left: 18px; | |
| } | |
| .timeline-item { | |
| display: flex; | |
| gap: 14px; | |
| align-items: flex-start; | |
| margin-bottom: 12px; | |
| } | |
| .timeline-time { | |
| min-width: 70px; | |
| color: var(--navy); | |
| font-weight: 800; | |
| } | |
| .timeline-task { | |
| color: #374151; | |
| } | |
| .strategy-box, .mission-box { | |
| background: #F8FAFC; | |
| border: 1px solid var(--border); | |
| border-radius: 18px; | |
| padding: 18px; | |
| margin-top: 18px; | |
| } | |
| .mission-box ul { | |
| margin: 0; | |
| padding-left: 20px; | |
| } | |
| .mission-box li { | |
| margin-bottom: 8px; | |
| } | |
| .footer-note { | |
| text-align: center; | |
| color: var(--muted); | |
| font-size: 13px; | |
| margin-top: 20px; | |
| } | |
| @media (max-width: 800px) { | |
| .hero-title { | |
| font-size: 34px; | |
| } | |
| #hero { | |
| padding: 34px 28px; | |
| } | |
| .summary-grid { | |
| grid-template-columns: 1fr; | |
| } | |
| } | |
| """ | |
| with gr.Blocks( | |
| css=custom_css, | |
| title="AI Study Assistant | AI-Scholars Final Project" | |
| ) as app: | |
| gr.HTML(""" | |
| <div id="hero"> | |
| <div class="hero-badge">AI Study Assistant | AI-Scholars Final Project</div> | |
| <h1 class="hero-title">Plan smarter study sessions in seconds.</h1> | |
| <p class="hero-subtitle"> | |
| Build a personalized study plan based on your subject, goal, time, difficulty, | |
| learning style, and stress level — designed to help students stay focused and get better results. | |
| </p> | |
| </div> | |
| """) | |
| with gr.Row(elem_id="main-panel"): | |
| with gr.Column(scale=1): | |
| gr.HTML(""" | |
| <div class="input-card"> | |
| <div class="section-title">Create Your Study Plan</div> | |
| <div class="section-subtitle">Enter a few details and get a focused, step-by-step session plan.</div> | |
| """) | |
| subject = gr.Textbox(label="Subject", placeholder="Biology, Math, History, Chemistry") | |
| goal = gr.Textbox(label="Study Goal", placeholder="Prepare for quiz on photosynthesis") | |
| time_available = gr.Textbox(label="Time Available", placeholder="60") | |
| difficulty = gr.Dropdown(["Easy", "Medium", "Hard"], label="Difficulty Level", value="Medium") | |
| learning_style = gr.Dropdown( | |
| ["Visual", "Practice-Based", "Verbal", "Reading/Writing"], | |
| label="Learning Style", | |
| value="Practice-Based" | |
| ) | |
| current_stress = gr.Dropdown(["Low", "Medium", "High"], label="Stress Level", value="Medium") | |
| submit = gr.Button("Generate Study Plan", elem_classes="primary-btn") | |
| gr.HTML("</div>") | |
| with gr.Column(scale=1, elem_classes="output-wrap"): | |
| output = gr.HTML(""" | |
| <div class="result-card"> | |
| <div class="result-topline">Your plan will appear here</div> | |
| <h2>Ready when you are.</h2> | |
| <p>Fill in the form and generate a personalized study plan built around your time, goal, and learning style.</p> | |
| </div> | |
| """) | |
| gr.HTML(""" | |
| <div class="footer-note"> | |
| Built for students who want structure, focus, and better study results. | |
| </div> | |
| """) | |
| submit.click( | |
| study_assistant, | |
| inputs=[subject, goal, time_available, difficulty, learning_style, current_stress], | |
| outputs=output | |
| ) | |
| app.launch() |