mimoha commited on
Commit
d67ec96
·
verified ·
1 Parent(s): 1e62bde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -20
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # app.py
2
  from google import genai
3
  import gradio as gr
4
 
@@ -7,14 +6,16 @@ API_KEY = "AIzaSyB4JKubDJd7nLx1NqPhDfMGeVWeQ7kqClY"
7
  client = genai.Client(api_key=API_KEY)
8
  MODEL_NAME = "gemini-2.5-flash"
9
 
10
-
11
- def generate_main_question_gemini(paragraph: str):
12
- if not paragraph or paragraph.strip() == "":
13
- return "الرجاء إدخال فقرة أولاً."
14
-
15
  prompt = f"""
16
- بناءا على
17
- {paragraph}
 
 
18
 
19
  المطلوب:
20
 
@@ -31,23 +32,44 @@ def generate_main_question_gemini(paragraph: str):
31
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
32
  return response.text.strip()
33
  except Exception as e:
34
- return f" Error while connecting to API: {e}"
35
 
36
 
37
  with gr.Blocks() as demo:
38
- gr.Markdown("## MainQuestionBasic Question Generator (Arabic Output)")
39
-
40
  with gr.Row():
41
- paragraph = gr.Textbox(
42
- label="Paragraph (Input text)",
43
- lines=8,
44
- placeholder="Paste the paragraph here..."
45
  )
46
-
47
- output = gr.Textbox(label="Generated Question (Arabic)", lines=3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- submit_btn = gr.Button("Submit")
50
- submit_btn.click(fn=generate_main_question_gemini, inputs=paragraph, outputs=output)
 
 
 
 
51
 
52
  if __name__ == "__main__":
53
- demo.launch(share=True, show_error=True)
 
 
1
  from google import genai
2
  import gradio as gr
3
 
 
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
 
 
32
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
33
  return response.text.strip()
34
  except Exception as e:
35
+ return f"Error while connecting to API: {e}"
36
 
37
 
38
  with gr.Blocks() as demo:
39
+ gr.Markdown("## جدول الدراسة منظم تلقائي (Arabic Output)")
40
+
41
  with gr.Row():
42
+ subjects_input = gr.Textbox(
43
+ label="أسماء المواد الدراسية",
44
+ placeholder="مثال: رياضيات، فيزياء، كيمياء",
45
+ lines=2
46
  )
47
+ lessons_input = gr.Textbox(
48
+ label="عدد الدروس أو الفصول في كل مادة",
49
+ placeholder="مثال: 10، 8، 12",
50
+ lines=2
51
+ )
52
+
53
+ with gr.Row():
54
+ days_input = gr.Textbox(
55
+ label="عدد الأيام المتاحة للدراسة",
56
+ placeholder="مثال: 7",
57
+ lines=1
58
+ )
59
+ hours_input = gr.Textbox(
60
+ label="عدد الساعات المتاحة للدراسة في كل يوم",
61
+ placeholder="مثال: 4",
62
+ lines=1
63
+ )
64
+
65
+ output = gr.Textbox(label="الجدول الناتج (باراغراف)", lines=10)
66
 
67
+ submit_btn = gr.Button("إنشاء الجدول")
68
+ submit_btn.click(
69
+ fn=generate_study_schedule,
70
+ inputs=[subjects_input, lessons_input, days_input, hours_input],
71
+ outputs=output
72
+ )
73
 
74
  if __name__ == "__main__":
75
+ demo.launch(share=True, show_error=True)