Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,20 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from mistralai import Mistral
|
| 4 |
|
| 5 |
-
|
| 6 |
-
api_key = os.environ
|
| 7 |
-
client = Mistral(api_key=api_key)
|
| 8 |
model_name = "open-mistral-nemo"
|
| 9 |
|
| 10 |
-
|
| 11 |
def generate_question(text):
|
| 12 |
-
|
| 13 |
prompt = f"""
|
| 14 |
-
بصفتك خبيراً في صياغة المناهج والتعلم النشط
|
| 15 |
-
|
| 16 |
-
وحدة الموضوع (Integrative Synthesis): لا تسأل عن تفاصيل مبعثرة، بل ابحث عن "الخيط الرفيع" الذي يربط كل أجزاء النص وصغ سؤالاً يجمعها في إطار واحد.
|
| 17 |
-
|
| 18 |
-
الربط بين العلة والنتيجة (Mechanism & Outcome): ركز على "لماذا وكيف" يؤدي التركيب أو السبب المذكور في النص إلى النتيجة أو الظاهرة الموصوفة.
|
| 19 |
-
|
| 20 |
-
تنشيط التفكير التحليلي: تجنب أسئلة (ماذا، عدد، اذكر). ابدأ السؤال بكلمات مثل: (كيف يفسر...؟، ما العلاقة الديناميكية بين...؟، كيف يتدرج...؟)، بحيث يضطر عقلي لتركيب الإجابة لا سردها.
|
| 21 |
-
|
| 22 |
-
الشمولية الاستراتيجية: يجب أن تكون الإجابة المثالية على هذا السؤال كفيلة بتغطية 80% إلى 90% من المعلومات الرئيسية الواردة في النص.
|
| 23 |
-
|
| 24 |
-
إليك النص الذي سأقوم بتسميعه:
|
| 25 |
{text}
|
| 26 |
-
|
| 27 |
السؤال:
|
| 28 |
"""
|
| 29 |
-
|
| 30 |
try:
|
|
|
|
| 31 |
response = client.chat.complete(
|
| 32 |
model=model_name,
|
| 33 |
messages=[
|
|
@@ -36,27 +23,19 @@ def generate_question(text):
|
|
| 36 |
temperature=0.3
|
| 37 |
)
|
| 38 |
|
|
|
|
| 39 |
return response.choices[0].message.content
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
return f"حدث خطأ: {e}"
|
| 43 |
|
| 44 |
-
|
| 45 |
-
# Gradio UI
|
| 46 |
demo = gr.Interface(
|
| 47 |
fn=generate_question,
|
| 48 |
-
inputs=[
|
| 49 |
-
|
| 50 |
-
lines=10,
|
| 51 |
-
label="الفقرة"
|
| 52 |
-
)
|
| 53 |
-
],
|
| 54 |
-
outputs=gr.Textbox(
|
| 55 |
-
lines=14,
|
| 56 |
-
label="السؤال المولد"
|
| 57 |
-
),
|
| 58 |
title="مولد الأسئلة العربية باستخدام Mistral Nemo",
|
| 59 |
-
description="أدخل عنوان الدرس والفقرة وسيتم توليد سؤال شامل."
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from mistralai import Mistral # Correct for version 1.0.0+
|
| 4 |
|
| 5 |
+
# Use the environment variable key you set in Hugging Face Settings
|
| 6 |
+
api_key = os.environ.get("MISTRAL_API_KEY")
|
| 7 |
+
client = Mistral(api_key=api_key) # Changed from MistralClient
|
| 8 |
model_name = "open-mistral-nemo"
|
| 9 |
|
|
|
|
| 10 |
def generate_question(text):
|
|
|
|
| 11 |
prompt = f"""
|
| 12 |
+
بصفتك خبيراً في صياغة المناهج والتعلم النشط...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
{text}
|
|
|
|
| 14 |
السؤال:
|
| 15 |
"""
|
|
|
|
| 16 |
try:
|
| 17 |
+
# The new SDK uses client.chat.complete
|
| 18 |
response = client.chat.complete(
|
| 19 |
model=model_name,
|
| 20 |
messages=[
|
|
|
|
| 23 |
temperature=0.3
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# Accessing content is slightly different in the new SDK
|
| 27 |
return response.choices[0].message.content
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
return f"حدث خطأ: {e}"
|
| 31 |
|
| 32 |
+
# Gradio UI remains mostly the same
|
|
|
|
| 33 |
demo = gr.Interface(
|
| 34 |
fn=generate_question,
|
| 35 |
+
inputs=[gr.Textbox(lines=10, label="الفقرة")],
|
| 36 |
+
outputs=[gr.Textbox(lines=14, label="السؤال المولد")],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
title="مولد الأسئلة العربية باستخدام Mistral Nemo",
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
demo.launch()
|