mimoha commited on
Commit
b01502c
·
verified ·
1 Parent(s): 3f0b6cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -29
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from google import genai
2
  import gradio as gr
3
 
@@ -6,21 +7,21 @@ API_KEY = "AIzaSyB4JKubDJd7nLx1NqPhDfMGeVWeQ7kqClY"
6
  client = genai.Client(api_key=API_KEY)
7
  MODEL_NAME = "gemini-2.5-flash"
8
 
9
- def generate_study_schedule(subjects, lessons, days, hours_per_day):
10
- # التحقق من الإدخالات
11
- if not subjects.strip() or not lessons.strip() or not days.strip() or not hours_per_day.strip():
12
- return "الرجاء ملء جميع الحقول أولاً."
13
-
14
  prompt = f"""
15
- المواد الدراسية: {subjects}
16
- عدد الدروس أو الفصول لكل مادة: {lessons}
17
- عدد الأيام المتاحة للدراسة: {days}
18
  عدد الساعات المتاحة للدراسة في كل يوم: {hours_per_day}
19
 
20
  المطلوب:
21
  اقترح جدول دراسي لتغطية المعطيات السابقة
22
  اعرض النتيجة بشكل سردي وواضح فقط.
23
  اكتب فقط البرنامج بدون اي عبارات اضافية.
 
24
  """
25
  try:
26
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
@@ -29,41 +30,34 @@ def generate_study_schedule(subjects, lessons, days, hours_per_day):
29
  return f"Error while connecting to API: {e}"
30
 
31
 
32
- with gr.Blocks() as demo:
33
- gr.Markdown("## جدول الدراسةمنظم تلقائي (Arabic Output)")
34
 
35
  with gr.Row():
36
  subjects_input = gr.Textbox(
37
- label="أسماء المواد الدراسية",
38
- placeholder="مثال: رياضيات، فيزياء، كيمياء",
39
  lines=2
40
  )
41
- lessons_input = gr.Textbox(
42
- label="عدد الدروس أو الفصول في كل مادة",
43
- placeholder="مثال: 10، 8، 12",
44
- lines=2
45
- )
46
-
47
- with gr.Row():
48
  days_input = gr.Textbox(
49
- label="عدد الأيام المتاحة للدراسة",
50
- placeholder="مثال: 7",
51
  lines=1
52
  )
53
  hours_input = gr.Textbox(
54
- label="عدد الساعات المتاحة للدراسة في كل يوم",
55
- placeholder="مثال: 4",
56
  lines=1
57
  )
58
 
59
- output = gr.Textbox(label="الجدول الناتج (باراغراف)", lines=10)
60
 
61
- submit_btn = gr.Button("إنشاء الجدول")
62
- submit_btn.click(
63
  fn=generate_study_schedule,
64
- inputs=[subjects_input, lessons_input, days_input, hours_input],
65
- outputs=output
66
  )
67
 
68
  if __name__ == "__main__":
69
- demo.launch(share=True, show_error=True)
 
1
+ # app.py
2
  from google import genai
3
  import gradio as gr
4
 
 
7
  client = genai.Client(api_key=API_KEY)
8
  MODEL_NAME = "gemini-2.5-flash"
9
 
10
+ def generate_study_schedule(subject_names, available_days, hours_per_day):
11
+ # Check inputs
12
+ if not subject_names.strip() or not available_days.strip() or not hours_per_day.strip():
13
+ return "Please fill in all fields first."
14
+
15
  prompt = f"""
16
+ المواد الدراسية: {subject_names}
17
+ عدد الأيام المتاحة للدراسة: {available_days}
 
18
  عدد الساعات المتاحة للدراسة في كل يوم: {hours_per_day}
19
 
20
  المطلوب:
21
  اقترح جدول دراسي لتغطية المعطيات السابقة
22
  اعرض النتيجة بشكل سردي وواضح فقط.
23
  اكتب فقط البرنامج بدون اي عبارات اضافية.
24
+
25
  """
26
  try:
27
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
 
30
  return f"Error while connecting to API: {e}"
31
 
32
 
33
+ with gr.Blocks() as app:
34
+ gr.Markdown("## Space Study Program Auto Study Schedule Generator")
35
 
36
  with gr.Row():
37
  subjects_input = gr.Textbox(
38
+ label="Subject Names",
39
+ placeholder="Example: Math, Physics, Chemistry",
40
  lines=2
41
  )
 
 
 
 
 
 
 
42
  days_input = gr.Textbox(
43
+ label="Available Days",
44
+ placeholder="Example: 7",
45
  lines=1
46
  )
47
  hours_input = gr.Textbox(
48
+ label="Study Hours per Day",
49
+ placeholder="Example: 4",
50
  lines=1
51
  )
52
 
53
+ schedule_output = gr.Textbox(label="Generated Study Schedule (Paragraph)", lines=10)
54
 
55
+ generate_btn = gr.Button("Generate Schedule")
56
+ generate_btn.click(
57
  fn=generate_study_schedule,
58
+ inputs=[subjects_input, days_input, hours_input],
59
+ outputs=schedule_output
60
  )
61
 
62
  if __name__ == "__main__":
63
+ app.launch(share=True, show_error=True)