Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,16 @@ import os
|
|
3 |
from deep_translator import GoogleTranslator
|
4 |
from huggingface_hub import InferenceClient
|
5 |
|
6 |
-
# دریافت توکن از محیط (در Hugging Face Secrets تنظیم شود)
|
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 |
base_prompt = (
|
21 |
f"Suggest 3 academic thesis topics based on the following:\n"
|
22 |
f"Field: {field}\n"
|
@@ -25,22 +21,16 @@ def generate_topics(field, major, keywords, audience, level):
|
|
25 |
f"Target Audience: {audience}\n"
|
26 |
f"Level: {level}\n"
|
27 |
)
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
else:
|
36 |
-
extra = (
|
37 |
-
"Focus on practical and applied thesis topics suitable for a master's level student."
|
38 |
-
)
|
39 |
-
|
40 |
prompt = base_prompt + extra
|
41 |
|
42 |
try:
|
43 |
-
# فراخوانی مدل DeepSeek با endpoint چت
|
44 |
response = hf_client.chat.completions.create(
|
45 |
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
46 |
messages=[
|
@@ -52,20 +42,17 @@ def generate_topics(field, major, keywords, audience, level):
|
|
52 |
)
|
53 |
english_output = response.choices[0].message.content.strip()
|
54 |
|
55 |
-
# ترجمه به فارسی
|
56 |
try:
|
57 |
-
|
58 |
-
except
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
"".join(f"<li>{line}</li>" for line in translated_output.split("\n") if line) + \
|
64 |
-
"</ol>"
|
65 |
|
66 |
return (
|
67 |
"<div>"
|
68 |
-
f"{
|
69 |
"<br><br>📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:<br>"
|
70 |
"<strong>021-88252497</strong>"
|
71 |
"</div>"
|
@@ -86,6 +73,7 @@ iface = gr.Interface(
|
|
86 |
],
|
87 |
outputs=gr.HTML(label="موضوعات پیشنهادی", elem_id="output_box"),
|
88 |
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین",
|
|
|
89 |
theme="default",
|
90 |
css="""
|
91 |
#output_box {
|
@@ -106,5 +94,4 @@ iface = gr.Interface(
|
|
106 |
)
|
107 |
|
108 |
if __name__ == "__main__":
|
109 |
-
# برای لینک عمومی: iface.launch(share=True)
|
110 |
iface.launch()
|
|
|
3 |
from deep_translator import GoogleTranslator
|
4 |
from huggingface_hub import InferenceClient
|
5 |
|
|
|
6 |
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
|
7 |
if not HF_TOKEN:
|
8 |
raise RuntimeError("Missing HUGGINGFACE_API_TOKEN secret")
|
9 |
|
|
|
10 |
hf_client = InferenceClient(token=HF_TOKEN)
|
11 |
|
12 |
def generate_topics(field, major, keywords, audience, level):
|
|
|
13 |
if not all([field.strip(), major.strip(), keywords.strip(), audience.strip()]):
|
14 |
return "<div style='color: red;'>❌ لطفاً همه فیلدها را پر کنید.</div>"
|
15 |
|
|
|
16 |
base_prompt = (
|
17 |
f"Suggest 3 academic thesis topics based on the following:\n"
|
18 |
f"Field: {field}\n"
|
|
|
21 |
f"Target Audience: {audience}\n"
|
22 |
f"Level: {level}\n"
|
23 |
)
|
24 |
+
extra = (
|
25 |
+
"Since this is a doctoral-level project, focus on proposing theoretical frameworks, "
|
26 |
+
"advanced modeling approaches, and in-depth methodological contributions."
|
27 |
+
if level == "دکتری"
|
28 |
+
else
|
29 |
+
"Focus on practical and applied thesis topics suitable for a master's level student."
|
30 |
+
)
|
|
|
|
|
|
|
|
|
|
|
31 |
prompt = base_prompt + extra
|
32 |
|
33 |
try:
|
|
|
34 |
response = hf_client.chat.completions.create(
|
35 |
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
36 |
messages=[
|
|
|
42 |
)
|
43 |
english_output = response.choices[0].message.content.strip()
|
44 |
|
|
|
45 |
try:
|
46 |
+
translated = GoogleTranslator(source='en', target='fa').translate(english_output)
|
47 |
+
except:
|
48 |
+
translated = english_output
|
49 |
|
50 |
+
items = [f"<li>{line}</li>" for line in translated.split("\n") if line.strip()]
|
51 |
+
translated_html = "<ol>" + "".join(items) + "</ol>"
|
|
|
|
|
52 |
|
53 |
return (
|
54 |
"<div>"
|
55 |
+
f"{translated_html}"
|
56 |
"<br><br>📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:<br>"
|
57 |
"<strong>021-88252497</strong>"
|
58 |
"</div>"
|
|
|
73 |
],
|
74 |
outputs=gr.HTML(label="موضوعات پیشنهادی", elem_id="output_box"),
|
75 |
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین",
|
76 |
+
description="", # ← مسیر لوگو
|
77 |
theme="default",
|
78 |
css="""
|
79 |
#output_box {
|
|
|
94 |
)
|
95 |
|
96 |
if __name__ == "__main__":
|
|
|
97 |
iface.launch()
|