File size: 3,767 Bytes
2543f2c
f35dc2e
8c853ac
88a1e0a
2543f2c
88a1e0a
 
 
 
 
 
 
 
 
 
4f768b5
2aca398
88a1e0a
2543f2c
88a1e0a
 
 
 
 
f35dc2e
 
 
 
 
 
 
1c68ea4
2543f2c
f35dc2e
88a1e0a
 
 
 
f35dc2e
88a1e0a
 
 
 
 
 
 
 
f35dc2e
88a1e0a
 
 
 
f35dc2e
 
2aca398
f35dc2e
 
2aca398
 
f35dc2e
 
 
 
 
88a1e0a
f35dc2e
88a1e0a
2543f2c
 
 
88a1e0a
 
 
 
f35dc2e
2543f2c
88a1e0a
2aca398
 
 
 
 
 
 
88a1e0a
 
2aca398
 
 
 
 
 
 
 
 
2543f2c
 
88a1e0a
 
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
import gradio as gr
import os
from deep_translator import GoogleTranslator
from huggingface_hub import InferenceApi

# دریافت کلید از محیط (در Hugging Face از Secrets استفاده کنید)
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
if not HF_TOKEN:
    raise RuntimeError("Missing HUGGINGFACE_API_TOKEN secret")

# ایجاد کلاینت برای تماس با مدل DeepSeek
hf_api = InferenceApi(
    repo_id="deepseek-ai/DeepSeek-Prover-V2-671B",
    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>"

    # ساخت پرامپت
    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}"
    )

    try:
        # فراخوانی مدل DeepSeek
        response = hf_api(
            inputs=prompt,
            parameters={"max_new_tokens": 512, "temperature": 0.7}
        )
        # استخراج متن پاسخ (در صورت نیاز به تنظیم بر اساس فرمت خروجی)
        english_output = response[0]['generated_text'].strip() if isinstance(response, list) else response.strip()

        # ترجمه به فارسی
        try:
            translated_output = GoogleTranslator(source='en', target='fa').translate(english_output)
        except Exception:
            translated_output = english_output

        # قالب‌بندی خروجی HTML
        translated_output_html = "<ol>" + \
            "".join(f"<li>{line}</li>" for line in translated_output.split("\n") if line) + \
            "</ol>"

        html_output = (
            "<div>"
            f"{translated_output_html}"
            "<br><br>📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:<br>"
            "<strong>021-88252497</strong>"
            "</div>"
        )

        return html_output

    except Exception as e:
        return f"<div style='color: red;'>❌ خطا در تماس با مدل DeepSeek: {e}</div>"

# رابط کاربری Gradio
iface = gr.Interface(
    fn=generate_topics,
    inputs=[
        gr.Textbox(label="رشته", placeholder="مثال: کامپیوتر"),
        gr.Textbox(label="گرایش", placeholder="مثال: هوش مصنوعی"),
        gr.Textbox(label="کلیدواژه‌ها", placeholder="مثال: یادگیری عمیق، بینایی ماشین"),
        gr.Textbox(label="جامعه هدف", placeholder="مثال: دانشجویان دکتری"),
        gr.Dropdown(["کارشناسی ارشد", "دکتری"], label="مقطع")
    ],
    outputs=gr.HTML(label="موضوعات پیشنهادی", elem_id="output_box"),
    title="🎓 پیشنهادگر موضوع پایان‌نامه کاسپین",
    theme="default",
    css="""
        #output_box {
            min-height: 350px !important;
            max-height: 600px !important;
            overflow-y: auto !important;
            background-color: #1e1e1e !important;
            color: white !important;
            padding: 20px;
            border: 2px solid #ccc;
            font-family: 'Tahoma', sans-serif;
            font-size: 16px;
            text-align: right;
            direction: rtl;
            line-height: 1.8;
        }
    """
)

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