Spaces:
Sleeping
Sleeping
| # app.py | |
| from google import genai | |
| import gradio as gr | |
| API_KEY = "AIzaSyB4JKubDJd7nLx1NqPhDfMGeVWeQ7kqClY" | |
| client = genai.Client(api_key=API_KEY) | |
| MODEL_NAME = "gemini-2.5-flash" | |
| def generate_study_schedule(subject_names, available_days, hours_per_day): | |
| # Check inputs | |
| if not subject_names.strip() or not available_days.strip() or not hours_per_day.strip(): | |
| return "Please fill in all fields first." | |
| prompt = f""" | |
| المواد الدراسية: {subject_names} | |
| عدد الأيام المتاحة للدراسة: {available_days} | |
| عدد الساعات المتاحة للدراسة في كل يوم: {hours_per_day} | |
| المطلوب: | |
| اقترح برنامج دراسي منطقي يراعي راحة واستيعاب الطالب لتغطية المعطيات السابقة مثل هذا التنسيق بالضبط : | |
| " | |
| يوم _ : | |
| __ : __ - __ :__ : فيزياء | |
| __ :__ - __ :__ : رياضيات | |
| __ :__ - __:__ : فيزياء | |
| " | |
| مع الاخذ بعين الاعتبار وجود استراحة حسب الساعات المتاحة | |
| اكتب فقط البرنامج بدون اي عبارات اضافية. | |
| """ | |
| try: | |
| response = client.models.generate_content(model=MODEL_NAME, contents=prompt) | |
| return response.text.strip() | |
| except Exception as e: | |
| return f"Error while connecting to API: {e}" | |
| with gr.Blocks() as app: | |
| gr.Markdown("## Space Study Program — Auto Study Schedule Generator") | |
| with gr.Row(): | |
| subjects_input = gr.Textbox( | |
| label="Subject Names", | |
| placeholder="Example: Math, Physics, Chemistry", | |
| lines=2 | |
| ) | |
| days_input = gr.Textbox( | |
| label="Available Days", | |
| placeholder="Example: 7", | |
| lines=1 | |
| ) | |
| hours_input = gr.Textbox( | |
| label="Study Hours per Day", | |
| placeholder="Example: 4", | |
| lines=1 | |
| ) | |
| schedule_output = gr.Textbox(label="Generated Study Schedule (Paragraph)", lines=10) | |
| generate_btn = gr.Button("Generate Schedule") | |
| generate_btn.click( | |
| fn=generate_study_schedule, | |
| inputs=[subjects_input, days_input, hours_input], | |
| outputs=schedule_output | |
| ) | |
| if __name__ == "__main__": | |
| app.launch(share=True, show_error=True) | |