Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,35 +2,44 @@
|
|
| 2 |
from google import genai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
API_KEY = "AIzaSyDedY-
|
| 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"⚠️
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|