MainQuestion / app.py
mimoha's picture
Update app.py
ea242be verified
raw
history blame
1.51 kB
# app.py
from google import genai
import gradio as gr
API_KEY = "gimin_mcq"
# نمرر المفتاح مباشرة
client = genai.Client(api_key=API_KEY)
MODEL_NAME = "gemini-1.5-flash"
def generate_main_question_gemini(paragraph: str, difficulty: str = "كتيير سهل"):
if not paragraph or paragraph.strip() == "":
return "رجاءً أدخل فقرة أولاً."
prompt = f"""
الفقرة التالية:
{paragraph}
المطلوب:
- بشكل بسيط أنشئ سؤالًا أساسيًا باللغة العربية (مستوى الصعوبة: {difficulty}).
"""
try:
response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
return response.text.strip()
except Exception as e:
return f"⚠️ حدث خطأ أثناء الاتصال بالـ API: {e}"
with gr.Blocks() as demo:
gr.Markdown("## MainQuestion — مولّد سؤال أساسي (عربي)")
paragraph = gr.Textbox(label="الفقرة (النص)", lines=8, placeholder="ألصق الفقرة هون...")
difficulty = gr.Dropdown(label="مستوى الصعوبة", choices=["كتيير سهل","سهل","متوسط","صعب"], value="كتيير سهل")
output = gr.Textbox(label="السؤال الأساسي", lines=3)
run_btn = gr.Button("إنشئ السؤال")
run_btn.click(fn=generate_main_question_gemini, inputs=[paragraph, difficulty], outputs=output)
if __name__ == "__main__":
demo.launch(share=True, show_error=True)