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 "
❌ لطفاً همه فیلدها را پر کنید.
" 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: # اینجا از 'input' به‌جای 'inputs' استفاده می‌کنیم result = hf_client.text_generation( model="deepseek-ai/DeepSeek-Prover-V2-671B", input=prompt, max_new_tokens=512, temperature=0.7 ) english_output = result.generated_text.strip() # ترجمه به فارسی try: translated_output = GoogleTranslator(source='en', target='fa').translate(english_output) except Exception: translated_output = english_output # قالب‌بندی HTML translated_output_html = "
    " + \ "".join(f"
  1. {line}
  2. " for line in translated_output.split("\n") if line) + \ "
" return ( "
" f"{translated_output_html}" "

📢 برای مشاوره تخصصی با کاسپین تماس بگیرید:
" "021-88252497" "
" ) except Exception as e: return f"
❌ خطا در تماس با مدل DeepSeek: {e}
" 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="🎓 پیشنهادگر موضوع پایان‌نامه کاسپین", 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()