Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,18 @@ import os
|
|
| 3 |
from deep_translator import GoogleTranslator
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
|
| 6 |
-
# دریافت توکن از محیط
|
| 7 |
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
|
| 8 |
if not HF_TOKEN:
|
| 9 |
raise RuntimeError("Missing HUGGINGFACE_API_TOKEN secret")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
hf_client = InferenceClient(token=HF_TOKEN)
|
| 13 |
|
| 14 |
def generate_topics(field, major, keywords, audience, level):
|
| 15 |
-
# اعتبارسنجی ورودیها
|
| 16 |
if not all([field.strip(), major.strip(), keywords.strip(), audience.strip()]):
|
| 17 |
return "<div style='color: red;'>❌ لطفاً همه فیلدها را پر کنید.</div>"
|
| 18 |
|
| 19 |
-
# ساخت پرامپت
|
| 20 |
prompt = (
|
| 21 |
f"Suggest 3 academic thesis topics based on the following:\n"
|
| 22 |
f"Field: {field}\n"
|
|
@@ -27,10 +25,10 @@ def generate_topics(field, major, keywords, audience, level):
|
|
| 27 |
)
|
| 28 |
|
| 29 |
try:
|
| 30 |
-
#
|
| 31 |
result = hf_client.text_generation(
|
| 32 |
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
| 33 |
-
|
| 34 |
max_new_tokens=512,
|
| 35 |
temperature=0.7
|
| 36 |
)
|
|
@@ -42,25 +40,22 @@ def generate_topics(field, major, keywords, audience, level):
|
|
| 42 |
except Exception:
|
| 43 |
translated_output = english_output
|
| 44 |
|
| 45 |
-
# قالببندی HTML
|
| 46 |
translated_output_html = "<ol>" + \
|
| 47 |
"".join(f"<li>{line}</li>" for line in translated_output.split("\n") if line) + \
|
| 48 |
"</ol>"
|
| 49 |
|
| 50 |
-
|
| 51 |
"<div>"
|
| 52 |
f"{translated_output_html}"
|
| 53 |
-
"<br><br>📢 برای مشاوره
|
| 54 |
"<strong>021-88252497</strong>"
|
| 55 |
"</div>"
|
| 56 |
)
|
| 57 |
|
| 58 |
-
return html_output
|
| 59 |
-
|
| 60 |
except Exception as e:
|
| 61 |
return f"<div style='color: red;'>❌ خطا در تماس با مدل DeepSeek: {e}</div>"
|
| 62 |
|
| 63 |
-
# رابط کاربری Gradio
|
| 64 |
iface = gr.Interface(
|
| 65 |
fn=generate_topics,
|
| 66 |
inputs=[
|
|
@@ -72,7 +67,6 @@ iface = gr.Interface(
|
|
| 72 |
],
|
| 73 |
outputs=gr.HTML(label="موضوعات پیشنهادی", elem_id="output_box"),
|
| 74 |
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین",
|
| 75 |
-
theme="default",
|
| 76 |
css="""
|
| 77 |
#output_box {
|
| 78 |
min-height: 350px !important;
|
|
@@ -92,5 +86,4 @@ iface = gr.Interface(
|
|
| 92 |
)
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|
| 95 |
-
# اگر نیاز به لینک عمومی دارید، share=True اضافه کنید
|
| 96 |
iface.launch()
|
|
|
|
| 3 |
from deep_translator import GoogleTranslator
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
|
| 6 |
+
# دریافت توکن از محیط
|
| 7 |
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
|
| 8 |
if not HF_TOKEN:
|
| 9 |
raise RuntimeError("Missing HUGGINGFACE_API_TOKEN secret")
|
| 10 |
|
| 11 |
+
# ساخت کلاینت
|
| 12 |
hf_client = InferenceClient(token=HF_TOKEN)
|
| 13 |
|
| 14 |
def generate_topics(field, major, keywords, audience, level):
|
|
|
|
| 15 |
if not all([field.strip(), major.strip(), keywords.strip(), audience.strip()]):
|
| 16 |
return "<div style='color: red;'>❌ لطفاً همه فیلدها را پر کنید.</div>"
|
| 17 |
|
|
|
|
| 18 |
prompt = (
|
| 19 |
f"Suggest 3 academic thesis topics based on the following:\n"
|
| 20 |
f"Field: {field}\n"
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
try:
|
| 28 |
+
# اینجا از 'input' بهجای 'inputs' استفاده میکنیم
|
| 29 |
result = hf_client.text_generation(
|
| 30 |
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
| 31 |
+
input=prompt,
|
| 32 |
max_new_tokens=512,
|
| 33 |
temperature=0.7
|
| 34 |
)
|
|
|
|
| 40 |
except Exception:
|
| 41 |
translated_output = english_output
|
| 42 |
|
| 43 |
+
# قالببندی HTML
|
| 44 |
translated_output_html = "<ol>" + \
|
| 45 |
"".join(f"<li>{line}</li>" for line in translated_output.split("\n") if line) + \
|
| 46 |
"</ol>"
|
| 47 |
|
| 48 |
+
return (
|
| 49 |
"<div>"
|
| 50 |
f"{translated_output_html}"
|
| 51 |
+
"<br><br>📢 برای مشاوره تخصصی با کاسپین تماس بگیرید:<br>"
|
| 52 |
"<strong>021-88252497</strong>"
|
| 53 |
"</div>"
|
| 54 |
)
|
| 55 |
|
|
|
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
return f"<div style='color: red;'>❌ خطا در تماس با مدل DeepSeek: {e}</div>"
|
| 58 |
|
|
|
|
| 59 |
iface = gr.Interface(
|
| 60 |
fn=generate_topics,
|
| 61 |
inputs=[
|
|
|
|
| 67 |
],
|
| 68 |
outputs=gr.HTML(label="موضوعات پیشنهادی", elem_id="output_box"),
|
| 69 |
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین",
|
|
|
|
| 70 |
css="""
|
| 71 |
#output_box {
|
| 72 |
min-height: 350px !important;
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
|
|
|
| 89 |
iface.launch()
|