import os import datetime import gradio as gr from groq import Groq # Get API key from HuggingFace Secrets GROQ_API_KEY = os.getenv("GROQ_API_KEY") client = Groq(api_key=GROQ_API_KEY) def generate_study_plan(subjects, dates, difficulty, preparation): try: today = datetime.date.today() subject_list = [s.strip() for s in subjects.split(",")] date_list = [d.strip() for d in dates.split(",")] difficulty_list = [d.strip() for d in difficulty.split(",")] prep_list = [p.strip() for p in preparation.split(",")] if not (len(subject_list) == len(date_list) == len(difficulty_list) == len(prep_list)): return "❌ Please enter equal number of values in all fields.", "" weak_subjects = [] for i in range(len(subject_list)): if int(prep_list[i]) <= 2: weak_subjects.append(subject_list[i]) prompt = f""" Create a structured daily study timetable. Subjects: {subject_list} Difficulty: {difficulty_list} Preparation: {prep_list} Weak Subjects: {weak_subjects} Prioritize weak subjects. Make it day-wise. """ completion = client.chat.completions.create( model="llama-3.1-8b-instant", messages=[ {"role": "user", "content": prompt} ], ) ai_response = completion.choices[0].message.content reminder = f"🔥 Focus more on: {', '.join(weak_subjects)}" if weak_subjects else "🎯 You're doing great!" return ai_response, reminder except Exception as e: return f"⚠️ Error: {str(e)}", "" with gr.Blocks(theme=gr.themes.Soft()) as app: gr.Markdown("# 🎓 AI Study Planner") gr.Markdown("Plan Smart. Study Smart. Ace Exams 🚀") with gr.Row(): subjects = gr.Textbox(label="Subjects (comma separated)") dates = gr.Textbox(label="Exam Dates (YYYY-MM-DD, comma separated)") with gr.Row(): difficulty = gr.Textbox(label="Difficulty (Easy/Medium/Hard)") preparation = gr.Textbox(label="Preparation Level (1-5)") generate_btn = gr.Button("✨ Generate Timetable") output_plan = gr.Textbox(lines=15, label="Your AI Timetable") reminder_output = gr.Textbox(label="Reminder") generate_btn.click( generate_study_plan, inputs=[subjects, dates, difficulty, preparation], outputs=[output_plan, reminder_output] ) app.launch()