Spaces:
Sleeping
Sleeping
File size: 1,617 Bytes
bc818eb 575a82f 14e8e88 bc818eb 575a82f b60eeb1 ef3b7ef 14e8e88 bc818eb 83c8d25 14e8e88 83c8d25 14e8e88 83c8d25 506fe6f 83c8d25 506fe6f 83c8d25 575a82f 83c8d25 575a82f 83c8d25 b60eeb1 83c8d25 b60eeb1 83c8d25 575a82f bc818eb 575a82f 83c8d25 575a82f bc818eb 83c8d25 bc818eb 575a82f b60eeb1 575a82f b60eeb1 575a82f b60eeb1 575a82f b60eeb1 575a82f | 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 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() |