Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,13 +11,12 @@ if not HF_TOKEN:
|
|
| 11 |
# ساخت کلاینت جدید
|
| 12 |
hf_client = InferenceClient(token=HF_TOKEN)
|
| 13 |
|
| 14 |
-
# تابع تولید موضوعات پایاننامه
|
| 15 |
def generate_topics(field, major, keywords, audience, level):
|
| 16 |
# اعتبارسنجی ورودیها
|
| 17 |
if not all([field.strip(), major.strip(), keywords.strip(), audience.strip()]):
|
| 18 |
return "<div style='color: red;'>❌ لطفاً همه فیلدها را پر کنید.</div>"
|
| 19 |
|
| 20 |
-
#
|
| 21 |
base_prompt = (
|
| 22 |
f"Suggest 3 academic thesis topics based on the following:\n"
|
| 23 |
f"Field: {field}\n"
|
|
@@ -26,7 +25,8 @@ def generate_topics(field, major, keywords, audience, level):
|
|
| 26 |
f"Target Audience: {audience}\n"
|
| 27 |
f"Level: {level}\n"
|
| 28 |
)
|
| 29 |
-
|
|
|
|
| 30 |
if level == "دکتری":
|
| 31 |
extra = (
|
| 32 |
"Since this is a doctoral-level project, focus on proposing theoretical frameworks, "
|
|
@@ -36,6 +36,7 @@ def generate_topics(field, major, keywords, audience, level):
|
|
| 36 |
extra = (
|
| 37 |
"Focus on practical and applied thesis topics suitable for a master's level student."
|
| 38 |
)
|
|
|
|
| 39 |
prompt = base_prompt + extra
|
| 40 |
|
| 41 |
try:
|
|
@@ -53,17 +54,18 @@ def generate_topics(field, major, keywords, audience, level):
|
|
| 53 |
|
| 54 |
# ترجمه به فارسی
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
except Exception:
|
| 58 |
-
|
| 59 |
|
| 60 |
-
# قالببندی HTML
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
return (
|
| 65 |
"<div>"
|
| 66 |
-
f"{
|
| 67 |
"<br><br>📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:<br>"
|
| 68 |
"<strong>021-88252497</strong>"
|
| 69 |
"</div>"
|
|
@@ -72,48 +74,37 @@ def generate_topics(field, major, keywords, audience, level):
|
|
| 72 |
except Exception as e:
|
| 73 |
return f"<div style='color: red;'>❌ خطا در تماس با مدل DeepSeek: {e}</div>"
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
level = gr.Dropdown(["کارشناسی ارشد", "دکتری"], label="مقطع")
|
| 106 |
-
submit = gr.Button("🎯 پیشنهاد موضوع")
|
| 107 |
-
with gr.Column(scale=1):
|
| 108 |
-
spinner = gr.HTML("<div class='spinner'></div>")
|
| 109 |
-
output = gr.HTML(elem_id="output_box")
|
| 110 |
-
|
| 111 |
-
# اتصال دکمه به تابع
|
| 112 |
-
submit.click(
|
| 113 |
-
fn=generate_topics,
|
| 114 |
-
inputs=[field, major, keywords, audience, level],
|
| 115 |
-
outputs=output
|
| 116 |
-
)
|
| 117 |
|
| 118 |
if __name__ == "__main__":
|
| 119 |
-
|
|
|
|
|
|
| 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 |
f"Target Audience: {audience}\n"
|
| 26 |
f"Level: {level}\n"
|
| 27 |
)
|
| 28 |
+
|
| 29 |
+
# اگر دکتری است، تاکید روی ارائه الگو و مدلسازی پیچیدهتر
|
| 30 |
if level == "دکتری":
|
| 31 |
extra = (
|
| 32 |
"Since this is a doctoral-level project, focus on proposing theoretical frameworks, "
|
|
|
|
| 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:
|
|
|
|
| 54 |
|
| 55 |
# ترجمه به فارسی
|
| 56 |
try:
|
| 57 |
+
translated_output = GoogleTranslator(source='en', target='fa').translate(english_output)
|
| 58 |
except Exception:
|
| 59 |
+
translated_output = english_output
|
| 60 |
|
| 61 |
+
# قالببندی HTML بهصورت لیست مرتب
|
| 62 |
+
translated_output_html = "<ol>" + \
|
| 63 |
+
"".join(f"<li>{line}</li>" for line in translated_output.split("\n") if line) + \
|
| 64 |
+
"</ol>"
|
| 65 |
|
| 66 |
return (
|
| 67 |
"<div>"
|
| 68 |
+
f"{translated_output_html}"
|
| 69 |
"<br><br>📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:<br>"
|
| 70 |
"<strong>021-88252497</strong>"
|
| 71 |
"</div>"
|
|
|
|
| 74 |
except Exception as e:
|
| 75 |
return f"<div style='color: red;'>❌ خطا در تماس با مدل DeepSeek: {e}</div>"
|
| 76 |
|
| 77 |
+
# رابط کاربری Gradio
|
| 78 |
+
iface = gr.Interface(
|
| 79 |
+
fn=generate_topics,
|
| 80 |
+
inputs=[
|
| 81 |
+
gr.Textbox(label="رشته", placeholder="مثال: کامپیوتر"),
|
| 82 |
+
gr.Textbox(label="گرایش", placeholder="مثال: هوش مصنوعی"),
|
| 83 |
+
gr.Textbox(label="کلیدواژهها", placeholder="مثال: یادگیری عمیق، بینایی ماشین"),
|
| 84 |
+
gr.Textbox(label="جامعه هدف", placeholder="مثال: دانشجویان دکتری"),
|
| 85 |
+
gr.Dropdown(["کارشناسی ارشد", "دکتری"], label="مقطع")
|
| 86 |
+
],
|
| 87 |
+
outputs=gr.HTML(label="موضوعات پیشنهادی", elem_id="output_box"),
|
| 88 |
+
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین",
|
| 89 |
+
theme="default",
|
| 90 |
+
css="""
|
| 91 |
+
#output_box {
|
| 92 |
+
min-height: 350px !important;
|
| 93 |
+
max-height: 600px !important;
|
| 94 |
+
overflow-y: auto !important;
|
| 95 |
+
background-color: #1e1e1e !important;
|
| 96 |
+
color: white !important;
|
| 97 |
+
padding: 20px;
|
| 98 |
+
border: 2px solid #ccc;
|
| 99 |
+
font-family: 'Tahoma', sans-serif;
|
| 100 |
+
font-size: 16px;
|
| 101 |
+
text-align: right;
|
| 102 |
+
direction: rtl;
|
| 103 |
+
line-height: 1.8;
|
| 104 |
+
}
|
| 105 |
+
"""
|
| 106 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
+
# برای لینک عمومی: iface.launch(share=True)
|
| 110 |
+
iface.launch()
|