Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
from google import genai
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
API_KEY = "AIzaSyB4JKubDJd7nLx1NqPhDfMGeVWeQ7kqClY"
|
| 6 |
+
|
| 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 |
+
قم بتوليد جدول دراسي منسّق ي
|
| 21 |
+
1.وزّع الدروس على الأيام والساعات المتاحة بشكل متوازن.
|
| 22 |
+
2. إعطاء أولوية للمواد الأصعب أو الأقرب في موعد الامتحان (إن وُجد).
|
| 23 |
+
3. عرض الجدول داخل التطبيق بشكل واضح
|
| 24 |
+
4. إضافة مؤقت تركيز (Pomodoro Timer) بسيط: 25 دقيقة دراسة + 5 دقائق راحة.
|
| 25 |
+
5. عرض ملخّص في النهاية يوضح عدد الساعات لكل مادة.
|
| 26 |
+
|
| 27 |
+
"""
|
| 28 |
+
try:
|
| 29 |
+
response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
|
| 30 |
+
return response.text.strip()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f" Error while connecting to API: {e}"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
+
gr.Markdown("## MainQuestion — Basic Question Generator (Arabic Output)")
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
paragraph = gr.Textbox(
|
| 40 |
+
label="Paragraph (Input text)",
|
| 41 |
+
lines=8,
|
| 42 |
+
placeholder="Paste the paragraph here..."
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
output = gr.Textbox(label="Generated Question (Arabic)", lines=3)
|
| 46 |
+
|
| 47 |
+
submit_btn = gr.Button("Submit")
|
| 48 |
+
submit_btn.click(fn=generate_main_question_gemini, inputs=paragraph, outputs=output)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch(share=True, show_error=True)
|