mimoha commited on
Commit
fe221f0
·
verified ·
1 Parent(s): 57d2be4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -2,35 +2,44 @@
2
  from google import genai
3
  import gradio as gr
4
 
5
- API_KEY = "AIzaSyDedY-PdSeTyitSztgMl7MubbELhffNx7c"
6
 
7
  client = genai.Client(api_key=API_KEY)
8
- MODEL_NAME = "gemini-1.5-flash"
 
9
 
10
  def generate_main_question_gemini(paragraph: str):
11
  if not paragraph or paragraph.strip() == "":
12
- return "رجاءً أدخل فقرة أولاً."
13
 
14
  prompt = f"""
15
- الفقرة التالية:
16
  {paragraph}
17
 
18
- المطلوب:
19
- - بشكل بسيط أنشئ سؤالًا أساسيًا باللغة العربية (مستوى الصعوبة: كتيير سهل).
20
  """
21
  try:
22
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
23
  return response.text.strip()
24
  except Exception as e:
25
- return f"⚠️ حدث خطأ أثناء الاتصال بالـ API: {e}"
 
26
 
27
  with gr.Blocks() as demo:
28
- gr.Markdown("## MainQuestion — مولّد سؤال أساسي (عربي)")
29
- paragraph = gr.Textbox(label="الفقرة (النص)", lines=8, placeholder="ألصق الفقرة هون...")
30
- output = gr.Textbox(label="السؤال الأساسي", lines=3)
31
 
32
- # يعمل التوليد تلقائياً عند إدخال نص
33
- paragraph.change(fn=generate_main_question_gemini, inputs=paragraph, outputs=output)
 
 
 
 
 
 
 
 
 
34
 
35
  if __name__ == "__main__":
36
  demo.launch(share=True, show_error=True)
 
2
  from google import genai
3
  import gradio as gr
4
 
5
+ API_KEY = "AIzaSyDedY-PdSeTyitSztgMl7c"
6
 
7
  client = genai.Client(api_key=API_KEY)
8
+ MODEL_NAME = "gemini-1.5-flash"
9
+
10
 
11
  def generate_main_question_gemini(paragraph: str):
12
  if not paragraph or paragraph.strip() == "":
13
+ return "Please enter a paragraph first."
14
 
15
  prompt = f"""
16
+ The following paragraph:
17
  {paragraph}
18
 
19
+ Task:
20
+ - Generate one simple main question in Arabic (difficulty level: very easy).
21
  """
22
  try:
23
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
24
  return response.text.strip()
25
  except Exception as e:
26
+ return f"⚠️ Error while connecting to API: {e}"
27
+
28
 
29
  with gr.Blocks() as demo:
30
+ gr.Markdown("## MainQuestion — Basic Question Generator (Arabic)")
 
 
31
 
32
+ with gr.Row():
33
+ paragraph = gr.Textbox(
34
+ label="Paragraph (Input text)",
35
+ lines=8,
36
+ placeholder="Paste the paragraph here..."
37
+ )
38
+
39
+ output = gr.Textbox(label="Generated Question", lines=3)
40
+
41
+ submit_btn = gr.Button("Submit")
42
+ submit_btn.click(fn=generate_main_question_gemini, inputs=paragraph, outputs=output)
43
 
44
  if __name__ == "__main__":
45
  demo.launch(share=True, show_error=True)