Spaces:
Running
Running
Delete app.py
Browse files
app.py
DELETED
@@ -1,62 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import gradio as gr
|
3 |
-
from transformers import pipeline, MarianMTModel, MarianTokenizer
|
4 |
-
|
5 |
-
# گرفتن توکن از متغیر محیطی (برای Hugging Face API اگر نیاز بود)
|
6 |
-
token = os.environ.get("HF_TOKEN")
|
7 |
-
|
8 |
-
# ⬇️ مدل تولید متن انگلیسی (پیشنهاد موضوع)
|
9 |
-
text_gen = pipeline(
|
10 |
-
"text-generation",
|
11 |
-
model="google/gemma-2b-it", # نسخه سبک و سازگار
|
12 |
-
token=token
|
13 |
-
)
|
14 |
-
|
15 |
-
# ⬇️ مدل ترجمه انگلیسی به فارسی
|
16 |
-
translation_model_name = "Helsinki-NLP/opus-mt-en-fa-opus"
|
17 |
-
translator_tokenizer = MarianTokenizer.from_pretrained(translation_model_name)
|
18 |
-
translator_model = MarianMTModel.from_pretrained(translation_model_name)
|
19 |
-
|
20 |
-
def translate_to_persian(text):
|
21 |
-
inputs = translator_tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
22 |
-
translated = translator_model.generate(**inputs)
|
23 |
-
return translator_tokenizer.decode(translated[0], skip_special_tokens=True)
|
24 |
-
|
25 |
-
def generate_topics(field, major, keywords, audience, level):
|
26 |
-
# ساخت پرامپت برای مدل انگلیسی
|
27 |
-
prompt = f"""
|
28 |
-
Suggest 3 thesis topics in the field of {field}, with a specialization in {major},
|
29 |
-
related to the keywords "{keywords}", and targeting the audience "{audience}".
|
30 |
-
The academic level is {level}. Just list the topics briefly.
|
31 |
-
"""
|
32 |
-
|
33 |
-
# تولید متن توسط مدل زبان
|
34 |
-
raw_output = text_gen(prompt, max_new_tokens=250)[0]['generated_text']
|
35 |
-
|
36 |
-
# حذف متن prompt تکراری (اگر مدل تکرار کرد)
|
37 |
-
if raw_output.startswith(prompt.strip()):
|
38 |
-
raw_output = raw_output[len(prompt.strip()):].strip()
|
39 |
-
|
40 |
-
# ترجمه خروجی به فارسی
|
41 |
-
translated_output = translate_to_persian(raw_output.strip())
|
42 |
-
|
43 |
-
# افزودن پیام تبلیغاتی در پایان
|
44 |
-
final_output = translated_output + "\n\nبرای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:\n02188252497"
|
45 |
-
|
46 |
-
return final_output
|
47 |
-
|
48 |
-
# رابط Gradio
|
49 |
-
iface = gr.Interface(
|
50 |
-
fn=generate_topics,
|
51 |
-
inputs=[
|
52 |
-
gr.Textbox(label="رشته"),
|
53 |
-
gr.Textbox(label="گرایش"),
|
54 |
-
gr.Textbox(label="کلیدواژهها"),
|
55 |
-
gr.Textbox(label="جامعه هدف"),
|
56 |
-
gr.Dropdown(choices=["کارشناسی ارشد", "دکتری"], label="مقطع")
|
57 |
-
],
|
58 |
-
outputs="text",
|
59 |
-
title="پیشنهادگر هوشمند موضوع پایاننامه کاسپین 🎓"
|
60 |
-
)
|
61 |
-
|
62 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|