Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import json
|
|
| 6 |
# الحصول على المفتاح من متغيّر بيئي
|
| 7 |
API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
| 8 |
|
| 9 |
-
MODEL_NAME = "deepseek-chat" #
|
| 10 |
|
| 11 |
def generate_main_question_deepseek(paragraph: str):
|
| 12 |
if not paragraph or paragraph.strip() == "":
|
|
@@ -15,18 +15,19 @@ def generate_main_question_deepseek(paragraph: str):
|
|
| 15 |
prompt = f"""
|
| 16 |
الفقرة التالية:
|
| 17 |
{paragraph}
|
|
|
|
| 18 |
المطلوب:
|
| 19 |
اقرأ الفقرة السابقة،
|
| 20 |
-
اعتمادًا عليها قم بتوليد سؤال أساسي للفقرة ليكون مفتاحًا لعملية تسميع الطالب للفقرة
|
| 21 |
-
اكتب السؤال المولد فقط بدون شرح ولا أي تفسير
|
| 22 |
"""
|
| 23 |
|
| 24 |
payload = {
|
| 25 |
"model": MODEL_NAME,
|
| 26 |
-
"
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
}
|
| 31 |
|
| 32 |
headers = {
|
|
@@ -36,7 +37,7 @@ def generate_main_question_deepseek(paragraph: str):
|
|
| 36 |
|
| 37 |
try:
|
| 38 |
response = requests.post(
|
| 39 |
-
"https://api.deepseek.com/v1/completions",
|
| 40 |
headers=headers,
|
| 41 |
data=json.dumps(payload)
|
| 42 |
)
|
|
@@ -44,12 +45,12 @@ def generate_main_question_deepseek(paragraph: str):
|
|
| 44 |
return f"Error while connecting to API: {response.text}"
|
| 45 |
|
| 46 |
result = response.json()
|
| 47 |
-
|
| 48 |
-
return result["choices"][0]["text"].strip()
|
| 49 |
|
| 50 |
except Exception as e:
|
| 51 |
return f"Error while connecting to API: {e}"
|
| 52 |
|
|
|
|
| 53 |
with gr.Blocks() as demo:
|
| 54 |
gr.Markdown("## MainQuestion — Basic Question Generator (Arabic Output)")
|
| 55 |
|
|
|
|
| 6 |
# الحصول على المفتاح من متغيّر بيئي
|
| 7 |
API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
| 8 |
|
| 9 |
+
MODEL_NAME = "deepseek-chat" # الموديل العام المخصص للدردشة
|
| 10 |
|
| 11 |
def generate_main_question_deepseek(paragraph: str):
|
| 12 |
if not paragraph or paragraph.strip() == "":
|
|
|
|
| 15 |
prompt = f"""
|
| 16 |
الفقرة التالية:
|
| 17 |
{paragraph}
|
| 18 |
+
|
| 19 |
المطلوب:
|
| 20 |
اقرأ الفقرة السابقة،
|
| 21 |
+
اعتمادًا عليها قم بتوليد سؤال أساسي للفقرة ليكون مفتاحًا لعملية تسميع الطالب للفقرة.
|
| 22 |
+
اكتب السؤال المولد فقط بدون شرح ولا أي تفسير.
|
| 23 |
"""
|
| 24 |
|
| 25 |
payload = {
|
| 26 |
"model": MODEL_NAME,
|
| 27 |
+
"messages": [
|
| 28 |
+
{"role": "user", "content": prompt}
|
| 29 |
+
],
|
| 30 |
+
"max_tokens": 150
|
| 31 |
}
|
| 32 |
|
| 33 |
headers = {
|
|
|
|
| 37 |
|
| 38 |
try:
|
| 39 |
response = requests.post(
|
| 40 |
+
"https://api.deepseek.com/v1/chat/completions",
|
| 41 |
headers=headers,
|
| 42 |
data=json.dumps(payload)
|
| 43 |
)
|
|
|
|
| 45 |
return f"Error while connecting to API: {response.text}"
|
| 46 |
|
| 47 |
result = response.json()
|
| 48 |
+
return result["choices"][0]["message"]["content"].strip()
|
|
|
|
| 49 |
|
| 50 |
except Exception as e:
|
| 51 |
return f"Error while connecting to API: {e}"
|
| 52 |
|
| 53 |
+
|
| 54 |
with gr.Blocks() as demo:
|
| 55 |
gr.Markdown("## MainQuestion — Basic Question Generator (Arabic Output)")
|
| 56 |
|