Spaces:
Sleeping
Sleeping
File size: 1,559 Bytes
880879e 14cf237 880879e 2df4785 2e6648e fe221f0 880879e 57d2be4 880879e 432130e 880879e 432130e 880879e 432130e 7191826 392dde4 d697220 7191826 880879e 14cf237 fe221f0 880879e 432130e 57d2be4 fe221f0 432130e fe221f0 880879e |
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 |
# 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}
المطلوب:
اقرأ الفقرة الآتية بعناية، ثم أنشئ سؤالًا واحدًا فقط عنها، يكون عامًا
ومبنيًا بأسلوب لغوي فصيح ومناسب للمناهج الدراسية.
اختر نوع السؤال المناسب وفقًا لمحتوى الفقرة،
لا تكتب أكثر من سؤال واحد.
"""
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)
|