mimoha commited on
Commit
796d385
·
verified ·
1 Parent(s): d14b483

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+
5
+ API_KEY = os.getenv("HF_TOKEN")
6
+ MODEL_NAME = "zai-org/GLM-4.6"
7
+
8
+ def generate_main_question_gemini(paragraph: str):
9
+ if not paragraph or paragraph.strip() == "":
10
+ return "الرجاء إدخال فقرة أولاً."
11
+
12
+ prompt = f"""
13
+ الفقرة التالية:
14
+ {paragraph}
15
+ المطلوب:
16
+ اقرأ الفقرة السابقة ،
17
+ اعتمادا عليها قم بتوليد سؤال اساسي للفقرة ليكون مفتاحا لعملية تسميع الطالب للفقرة
18
+ اكتب السؤال المولد فقط بدون شرح ولا اي تفسير
19
+ """
20
+
21
+ try:
22
+ response = requests.post(
23
+ f"https://router.huggingface.co/hf-inference/models/{MODEL_NAME}",
24
+ headers={"Authorization": f"Bearer {API_KEY}"},
25
+ json={"inputs": prompt}
26
+ )
27
+
28
+ if response.status_code != 200:
29
+ return f"Error while connecting to API: {response.text}"
30
+
31
+ result = response.json()
32
+
33
+ if isinstance(result, list):
34
+ return result[0].get("generated_text", "").strip()
35
+
36
+ return "Unexpected response format."
37
+
38
+ except Exception as e:
39
+ return f"Error while connecting to API: {e}"
40
+
41
+
42
+ with gr.Blocks() as demo:
43
+ gr.Markdown("## MainQuestion — Basic Question Generator (Arabic Output)")
44
+
45
+ with gr.Row():
46
+ paragraph = gr.Textbox(
47
+ label="Paragraph (Input text)",
48
+ lines=8,
49
+ placeholder="Paste the paragraph here..."
50
+ )
51
+
52
+ output = gr.Textbox(label="Generated Question (Arabic)", lines=3)
53
+
54
+ submit_btn = gr.Button("Submit")
55
+ submit_btn.click(fn=generate_main_question_gemini, inputs=paragraph, outputs=output)
56
+
57
+ if __name__ == "__main__":
58
+ demo.launch(share=True, show_error=True)