File size: 4,487 Bytes
2543f2c
f35dc2e
8c853ac
097fb1d
2543f2c
bde0d38
88a1e0a
 
 
2365ad3
88a1e0a
2543f2c
88a1e0a
 
 
cad9104
f35dc2e
 
 
 
 
cad9104
1c68ea4
9c119e5
 
 
 
 
 
 
cad9104
 
f35dc2e
bde0d38
2365ad3
 
bde0d38
 
2365ad3
 
 
f35dc2e
bde0d38
88a1e0a
bde0d38
9c119e5
bde0d38
f35dc2e
bde0d38
 
ca87238
2aca398
bde0d38
9b37298
2aca398
 
f35dc2e
 
bde0d38
f35dc2e
314fbdf
c4c3804
 
 
 
 
 
 
 
 
 
314fbdf
bde0d38
b8972a9
 
314fbdf
c4c3804
314fbdf
b9e4088
314fbdf
 
 
 
 
 
c4c3804
eede593
 
bde0d38
 
eede593
c4c3804
 
 
 
 
 
 
 
14cf527
1bd73ac
 
 
 
 
 
 
bde0d38
1bd73ac
 
 
 
 
 
 
 
 
2543f2c
88a1e0a
1bd73ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import gradio as gr
import os
from deep_translator import GoogleTranslator
from huggingface_hub import InferenceClient

# دریافت توکن
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
if not HF_TOKEN:
    raise RuntimeError("Missing HUGGINGFACE_API_TOKEN secret")
hf_client = InferenceClient(token=HF_TOKEN)

def generate_topics(field, major, keywords, audience, level):
    if not all([field.strip(), major.strip(), keywords.strip(), audience.strip()]):
        return "<div style='color: red;'>❌ لطفاً همه فیلدها را پر کنید.</div>"

    base_prompt = (
        f"Suggest 3 academic thesis topics based on the following:\n"
        f"Field: {field}\n"
        f"Specialization: {major}\n"
        f"Keywords: {keywords}\n"
        f"Target Audience: {audience}\n"
        f"Level: {level}\n"
    )
    extra = (
        "Since this is a doctoral-level project, focus on proposing theoretical frameworks, "
        "advanced modeling approaches, and in-depth methodological contributions."
        if level == "دکتری"
        else
        "Focus on practical and applied thesis topics suitable for a master's level student."
    )
    prompt = base_prompt + extra

    try:
        resp = hf_client.chat.completions.create(
            model="deepseek-ai/DeepSeek-Prover-V2-671B",
            messages=[
                {"role":"system","content":"You are an academic advisor assistant."},
                {"role":"user","content":prompt}
            ],
            temperature=0.7,
            max_tokens=512
        )
        english = resp.choices[0].message.content.strip()
        try:
            translated = GoogleTranslator(source='en', target='fa').translate(english)
        except:
            translated = english

        items = [f"<li>{l}</li>" for l in translated.split("\n") if l.strip()]
        html = "<ol>" + "".join(items) + "</ol>"
        return (
            "<div>"
            f"{html}"
            "<br><br>📢 برای مشاوره تخصصی و ارائه موضوع های حرفه ای با کاسپین تماس بگیرید:<br>"
            "<strong>021-88252497</strong>"
            "</div>"
        )
    except Exception as e:
        return f"<div style='color: red;'>❌ خطا: {e}</div>"

# CSS سفارشی (سفید/مشکی + پنهان‌سازی فوتر + اصلاح باکس پاسخ)
custom_css = """
body, .gradio-container {
    background-color: white !important;
    color: black !important;
}
input, textarea, select, button {
    background-color: white !important;
    color: black !important;
    border: 1px solid #ccc !important;
}
/* تیتر و Markdown */
.markdown, .markdown h1, .markdown h2, .markdown h3, .markdown p {
    color: black !important;
}
/* باکس خروجی: پس‌زمینه کاملاً سفید و متن مشکی، شامل تمام زیرالمان‌ها */
#output_box {
    background-color: white !important;
    border: 1px solid #333 !important;
    padding: 15px !important;
    border-radius: 4px !important;
}
#output_box, 
#output_box * {
    color: black !important;
}
/* پنهان‌سازی کامل فوتر Gradio */
footer {
    display: none !important;
}
/* غیرفعال‌سازی تم تیره */
.gradio-container.dark {
    background-color: white !important;
    color: black !important;
}
"""

with gr.Blocks(css=custom_css, theme="default") as app:
    gr.Image(value="logo.png", interactive=False, show_label=False)
    gr.Markdown("## 🎓 پیشنهادگر موضوع پایان‌نامه کاسپین")

    with gr.Row():
        with gr.Column():
            field    = gr.Textbox(label="رشته", placeholder="مثال: کامپیوتر")
            major    = gr.Textbox(label="گرایش", placeholder="مثال: هوش مصنوعی")
            keywords = gr.Textbox(label="کلیدواژه‌ها", placeholder="مثال: یادگیری عمیق، بینایی ماشین")
            audience = gr.Textbox(label="جامعه هدف", placeholder="مثال: دانشجویان دکتری")
            level    = gr.Dropdown(["کارشناسی ارشد","دکتری"], label="مقطع")
            submit   = gr.Button("🎯 پیشنهاد موضوع")
        with gr.Column():
            output   = gr.HTML(elem_id="output_box")

    submit.click(
        fn=generate_topics,
        inputs=[field, major, keywords, audience, level],
        outputs=output
    )

if __name__ == "__main__":
    app.launch()