Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
| 10 |
-
#
|
| 11 |
-
if not
|
| 12 |
-
return "
|
| 13 |
-
|
| 14 |
prompt = f"""
|
| 15 |
-
المواد الدراسية: {
|
| 16 |
-
عدد
|
| 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
|
| 33 |
-
gr.Markdown("##
|
| 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="
|
| 51 |
lines=1
|
| 52 |
)
|
| 53 |
hours_input = gr.Textbox(
|
| 54 |
-
label="
|
| 55 |
-
placeholder="
|
| 56 |
lines=1
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
fn=generate_study_schedule,
|
| 64 |
-
inputs=[subjects_input,
|
| 65 |
-
outputs=
|
| 66 |
)
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
-
|
|
|
|
| 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)
|