Sammaali's picture
Update app.py
83c8d25 verified
import os
import gradio as gr
from mistralai.client import Mistral
api_key = os.environ["MISTRAL_API_KEY"]
client = Mistral(api_key=api_key)
model_name = "mistral-small-latest"
def generate_question(text):
prompt = f"""
You are an expert Arabic educational content designer.
TASK:
Generate ONE comprehensive question that covers the main ideas of the given text.
STRICT RULES:
1. The question must be:
- Clear and concise (maximum 25 words)
- Written in correct Modern Standard Arabic
- A single sentence only
2. The question should:
- Cover the main idea of the text
- Encourage recalling most key points
- NOT require listing every tiny detail
3. DO NOT:
- Repeat phrases
- Ask multiple questions
- Explain anything
- Add analysis or commentary
4. Output ONLY the question.
TEXT:
{text}
FINAL QUESTION:
"""
try:
response = client.chat.complete(
model=model_name,
messages=[{"role": "user", "content": prompt}],
temperature=0.2
)
return response.choices[0].message.content.strip()
except Exception as e:
return f"حدث خطأ: {e}"
# Gradio UI
demo = gr.Interface(
fn=generate_question,
inputs=[
gr.Textbox(
lines=10,
label="الفقرة"
)
],
outputs=gr.Textbox(
lines=14,
label="السؤال المولد"
),
title="مولد الأسئلة العربية باستخدام Mistral Nemo",
description="أدخل عنوان الدرس والفقرة وسيتم توليد سؤال شامل."
)
demo.launch()