File size: 1,701 Bytes
843886a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e62bde
 
 
 
 
 
 
 
843886a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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_main_question_gemini(paragraph: str):
    if not paragraph or paragraph.strip() == "":
        return "الرجاء إدخال فقرة أولاً."

    prompt = f"""
    بناءا على 
{paragraph}

المطلوب:

أنشئ جدول دراسة منظّم بحيث:
1. توزّع الدروس بالتساوي على الأيام والساعات.
2. تعطي أولوية للمواد الأصعب أو الأقرب امتحانها.
3. يكون العرض واضح داخل التطبيق.
4. تضيف مؤقت بومودورو (25 دقيقة دراسة + 5 راحة).
5. تذكر في النهاية ملخّص بعدد الساعات لكل مادة.

اعرض النتيجة بشكل سردي وواضح فقط.
"""
    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 demo:
    gr.Markdown("## MainQuestion — Basic Question Generator (Arabic Output)")
    
    with gr.Row():
        paragraph = gr.Textbox(
            label="Paragraph (Input text)", 
            lines=8, 
            placeholder="Paste the paragraph here..."
        )
    
    output = gr.Textbox(label="Generated Question (Arabic)", lines=3)

    submit_btn = gr.Button("Submit")
    submit_btn.click(fn=generate_main_question_gemini, inputs=paragraph, outputs=output)

if __name__ == "__main__":
    demo.launch(share=True, show_error=True)