Update app.py
Browse files
app.py
CHANGED
|
@@ -1,68 +1,48 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
-
import json
|
| 5 |
|
| 6 |
-
API_KEY = os.
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
return "الرجاء إدخال فقرة أولاً."
|
| 12 |
|
| 13 |
prompt = f"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
المطلوب:
|
| 18 |
-
اقرأ الفقرة السابقة،
|
| 19 |
-
اعتمادًا عليها قم بتوليد سؤال أساسي للفقرة ليكون مفتاحًا لعملية تسميع الطالب للفقرة.
|
| 20 |
-
اكتب السؤال المولد فقط بدون شرح ولا أي تفسير.
|
| 21 |
-
"""
|
| 22 |
-
|
| 23 |
-
payload = {
|
| 24 |
-
"model": MODEL_NAME,
|
| 25 |
-
"prompt": prompt,
|
| 26 |
-
"max_tokens": 150,
|
| 27 |
-
"temperature": 0.3
|
| 28 |
-
}
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
try:
|
| 36 |
-
response =
|
| 37 |
-
|
| 38 |
-
headers=headers,
|
| 39 |
-
data=json.dumps(payload)
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
if response.status_code != 200:
|
| 43 |
-
return f"Error while connecting to API: {response.text}"
|
| 44 |
-
|
| 45 |
-
result = response.json()
|
| 46 |
-
return result["choices"][0]["text"].strip()
|
| 47 |
-
|
| 48 |
except Exception as e:
|
| 49 |
-
return f"Error while connecting to API: {e}"
|
| 50 |
-
|
| 51 |
|
|
|
|
| 52 |
with gr.Blocks() as demo:
|
| 53 |
gr.Markdown("## MainQuestion — Basic Question Generator (Arabic Output)")
|
| 54 |
-
|
| 55 |
with gr.Row():
|
| 56 |
paragraph = gr.Textbox(
|
| 57 |
-
label="Paragraph (Input text)",
|
| 58 |
-
lines=8,
|
| 59 |
placeholder="Paste the paragraph here..."
|
| 60 |
)
|
| 61 |
-
|
| 62 |
output = gr.Textbox(label="Generated Question (Arabic)", lines=3)
|
| 63 |
|
| 64 |
submit_btn = gr.Button("Submit")
|
| 65 |
-
submit_btn.click(fn=
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|
| 68 |
demo.launch(share=True, show_error=True)
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from deepsea import DeepSeaClient
|
|
|
|
| 4 |
|
| 5 |
+
API_KEY = os.environ.get("DEEPSEA_API_KEY")
|
| 6 |
+
if not API_KEY:
|
| 7 |
+
raise ValueError("الرجاء وضع DEEPSEA_API_KEY في البيئة (Secrets على Hugging Face)")
|
| 8 |
|
| 9 |
+
client = DeepSeaClient(api_key=API_KEY)
|
| 10 |
+
MODEL_NAME = "text-generator-arabic"
|
| 11 |
+
|
| 12 |
+
def generate_main_question_deepsea(paragraph: str):
|
| 13 |
+
if not paragraph.strip():
|
| 14 |
return "الرجاء إدخال فقرة أولاً."
|
| 15 |
|
| 16 |
prompt = f"""
|
| 17 |
+
الفقرة التالية:
|
| 18 |
+
{paragraph}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
المطلوب:
|
| 21 |
+
اعتمادًا على الفقرة السابقة، قم بتوليد سؤال أساسي للفقرة ليكون مفتاحًا لعملية تسميع الطالب.
|
| 22 |
+
اكتب السؤال فقط بدون أي شرح أو تفسير.
|
| 23 |
+
"""
|
| 24 |
|
| 25 |
try:
|
| 26 |
+
response = client.generate_text(model=MODEL_NAME, prompt=prompt, max_tokens=150)
|
| 27 |
+
return response.text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
+
return f"Error while connecting to DeepSea API: {e}"
|
|
|
|
| 30 |
|
| 31 |
+
# واجهة Gradio
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
gr.Markdown("## MainQuestion — Basic Question Generator (Arabic Output)")
|
| 34 |
+
|
| 35 |
with gr.Row():
|
| 36 |
paragraph = gr.Textbox(
|
| 37 |
+
label="Paragraph (Input text)",
|
| 38 |
+
lines=8,
|
| 39 |
placeholder="Paste the paragraph here..."
|
| 40 |
)
|
| 41 |
+
|
| 42 |
output = gr.Textbox(label="Generated Question (Arabic)", lines=3)
|
| 43 |
|
| 44 |
submit_btn = gr.Button("Submit")
|
| 45 |
+
submit_btn.click(fn=generate_main_question_deepsea, inputs=paragraph, outputs=output)
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
demo.launch(share=True, show_error=True)
|