Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ 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")
|
|
@@ -31,58 +31,47 @@ def generate_topics(field, major, keywords, audience, level):
|
|
| 31 |
prompt = base_prompt + extra
|
| 32 |
|
| 33 |
try:
|
| 34 |
-
|
| 35 |
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
| 36 |
messages=[
|
| 37 |
-
{"role":
|
| 38 |
-
{"role":
|
| 39 |
],
|
| 40 |
temperature=0.7,
|
| 41 |
max_tokens=512
|
| 42 |
)
|
| 43 |
-
|
| 44 |
try:
|
| 45 |
-
translated = GoogleTranslator(source='en', target='fa').translate(
|
| 46 |
except:
|
| 47 |
-
translated =
|
| 48 |
-
|
| 49 |
-
items = [f"<li>{line}</li>" for line in translated.split("\n") if line.strip()]
|
| 50 |
-
translated_html = "<ol>" + "".join(items) + "</ol>"
|
| 51 |
|
|
|
|
|
|
|
| 52 |
return (
|
| 53 |
"<div>"
|
| 54 |
-
f"{
|
| 55 |
-
"<br><br>📢 برای مشاوره
|
| 56 |
"<strong>021-88252497</strong>"
|
| 57 |
"</div>"
|
| 58 |
)
|
| 59 |
except Exception as e:
|
| 60 |
-
return f"<div style='color: red;'>❌
|
| 61 |
|
| 62 |
-
# CSS سفارشی
|
| 63 |
custom_css = """
|
| 64 |
body, .gradio-container {
|
| 65 |
background-color: white !important;
|
| 66 |
color: black !important;
|
| 67 |
}
|
| 68 |
-
|
| 69 |
-
/* همه متون داخل ورودیها و دکمهها */
|
| 70 |
input, textarea, select, button {
|
| 71 |
background-color: white !important;
|
| 72 |
color: black !important;
|
| 73 |
border: 1px solid #ccc !important;
|
| 74 |
}
|
| 75 |
-
|
| 76 |
-
/* تیتر و متن Markdown بهصورت تضمینی مشکی */
|
| 77 |
-
.markdown,
|
| 78 |
-
.markdown h1,
|
| 79 |
-
.markdown h2,
|
| 80 |
-
.markdown h3,
|
| 81 |
-
.markdown p {
|
| 82 |
color: black !important;
|
| 83 |
}
|
| 84 |
-
|
| 85 |
-
/* باکس خروجی: پسزمینه روشن و حاشیه مشکی */
|
| 86 |
#output_box {
|
| 87 |
background-color: #f9f9f9 !important;
|
| 88 |
color: black !important;
|
|
@@ -90,8 +79,10 @@ input, textarea, select, button {
|
|
| 90 |
padding: 15px;
|
| 91 |
border-radius: 4px;
|
| 92 |
}
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
.gradio-container.dark {
|
| 96 |
background-color: white !important;
|
| 97 |
color: black !important;
|
|
@@ -99,9 +90,7 @@ input, textarea, select, button {
|
|
| 99 |
"""
|
| 100 |
|
| 101 |
with gr.Blocks(css=custom_css, theme="default") as app:
|
| 102 |
-
# لوگوی شما
|
| 103 |
gr.Image(value="logo.png", interactive=False, show_label=False)
|
| 104 |
-
# تیتر مشکی
|
| 105 |
gr.Markdown("## 🎓 پیشنهادگر موضوع پایاننامه کاسپین")
|
| 106 |
|
| 107 |
with gr.Row():
|
|
@@ -110,7 +99,7 @@ with gr.Blocks(css=custom_css, theme="default") as app:
|
|
| 110 |
major = gr.Textbox(label="گرایش", placeholder="مثال: هوش مصنوعی")
|
| 111 |
keywords = gr.Textbox(label="کلیدواژهها", placeholder="مثال: یادگیری عمیق، بینایی ماشین")
|
| 112 |
audience = gr.Textbox(label="جامعه هدف", placeholder="مثال: دانشجویان دکتری")
|
| 113 |
-
level = gr.Dropdown(["کارشناسی ارشد",
|
| 114 |
submit = gr.Button("🎯 پیشنهاد موضوع")
|
| 115 |
with gr.Column():
|
| 116 |
output = gr.HTML(elem_id="output_box")
|
|
|
|
| 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")
|
|
|
|
| 31 |
prompt = base_prompt + extra
|
| 32 |
|
| 33 |
try:
|
| 34 |
+
resp = hf_client.chat.completions.create(
|
| 35 |
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
| 36 |
messages=[
|
| 37 |
+
{"role":"system","content":"You are an academic advisor assistant."},
|
| 38 |
+
{"role":"user","content":prompt}
|
| 39 |
],
|
| 40 |
temperature=0.7,
|
| 41 |
max_tokens=512
|
| 42 |
)
|
| 43 |
+
english = resp.choices[0].message.content.strip()
|
| 44 |
try:
|
| 45 |
+
translated = GoogleTranslator(source='en', target='fa').translate(english)
|
| 46 |
except:
|
| 47 |
+
translated = english
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
items = [f"<li>{l}</li>" for l in translated.split("\n") if l.strip()]
|
| 50 |
+
html = "<ol>" + "".join(items) + "</ol>"
|
| 51 |
return (
|
| 52 |
"<div>"
|
| 53 |
+
f"{html}"
|
| 54 |
+
"<br><br>📢 برای مشاوره تخصصی با کاسپین تماس بگیرید:<br>"
|
| 55 |
"<strong>021-88252497</strong>"
|
| 56 |
"</div>"
|
| 57 |
)
|
| 58 |
except Exception as e:
|
| 59 |
+
return f"<div style='color: red;'>❌ خطا: {e}</div>"
|
| 60 |
|
| 61 |
+
# CSS سفارشی (سفید/مشکی + مخفی کردن فوتر)
|
| 62 |
custom_css = """
|
| 63 |
body, .gradio-container {
|
| 64 |
background-color: white !important;
|
| 65 |
color: black !important;
|
| 66 |
}
|
|
|
|
|
|
|
| 67 |
input, textarea, select, button {
|
| 68 |
background-color: white !important;
|
| 69 |
color: black !important;
|
| 70 |
border: 1px solid #ccc !important;
|
| 71 |
}
|
| 72 |
+
.markdown, .markdown h1, .markdown h2, .markdown h3, .markdown p {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
color: black !important;
|
| 74 |
}
|
|
|
|
|
|
|
| 75 |
#output_box {
|
| 76 |
background-color: #f9f9f9 !important;
|
| 77 |
color: black !important;
|
|
|
|
| 79 |
padding: 15px;
|
| 80 |
border-radius: 4px;
|
| 81 |
}
|
| 82 |
+
/* این قسمت را برای مخفی کردن فوتر اضافه کنید */
|
| 83 |
+
.gradio-container .footer {
|
| 84 |
+
display: none !important;
|
| 85 |
+
}
|
| 86 |
.gradio-container.dark {
|
| 87 |
background-color: white !important;
|
| 88 |
color: black !important;
|
|
|
|
| 90 |
"""
|
| 91 |
|
| 92 |
with gr.Blocks(css=custom_css, theme="default") as app:
|
|
|
|
| 93 |
gr.Image(value="logo.png", interactive=False, show_label=False)
|
|
|
|
| 94 |
gr.Markdown("## 🎓 پیشنهادگر موضوع پایاننامه کاسپین")
|
| 95 |
|
| 96 |
with gr.Row():
|
|
|
|
| 99 |
major = gr.Textbox(label="گرایش", placeholder="مثال: هوش مصنوعی")
|
| 100 |
keywords = gr.Textbox(label="کلیدواژهها", placeholder="مثال: یادگیری عمیق، بینایی ماشین")
|
| 101 |
audience = gr.Textbox(label="جامعه هدف", placeholder="مثال: دانشجویان دکتری")
|
| 102 |
+
level = gr.Dropdown(["کارشناسی ارشد","دکتری"], label="مقطع")
|
| 103 |
submit = gr.Button("🎯 پیشنهاد موضوع")
|
| 104 |
with gr.Column():
|
| 105 |
output = gr.HTML(elem_id="output_box")
|