Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,37 @@
|
|
| 1 |
import os
|
| 2 |
-
import re
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import pipeline
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
# تابع تشخیص و ترجمه کلمات انگلیسی رایج در حوزه روانشناسی
|
| 17 |
-
EN_FA_DICT = {
|
| 18 |
-
"behavior": "رفتار",
|
| 19 |
-
"self-esteem": "عزت نفس",
|
| 20 |
-
"confidence": "اعتماد به نفس",
|
| 21 |
-
"learning": "یادگیری",
|
| 22 |
-
"attachment": "دلبستگی",
|
| 23 |
-
"communication": "ارتباط",
|
| 24 |
-
"stress": "استرس",
|
| 25 |
-
"parent": "والد",
|
| 26 |
-
"trauma": "آسیب روانی"
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
def replace_english_words(text):
|
| 30 |
-
for eng, fa in EN_FA_DICT.items():
|
| 31 |
-
text = re.sub(rf"\b{eng}\b", fa, text, flags=re.IGNORECASE)
|
| 32 |
-
return text
|
| 33 |
|
| 34 |
def generate_topics(field, major, keywords, audience, level):
|
| 35 |
prompt = f"""
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
"""
|
| 39 |
-
output = pipe(prompt, max_new_tokens=250)[0]['generated_text']
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
output = output[len(prompt.strip()):].strip()
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
|
| 51 |
-
return
|
| 52 |
|
| 53 |
iface = gr.Interface(
|
| 54 |
fn=generate_topics,
|
|
@@ -60,7 +43,7 @@ iface = gr.Interface(
|
|
| 60 |
gr.Dropdown(choices=["کارشناسی ارشد", "دکتری"], label="مقطع")
|
| 61 |
],
|
| 62 |
outputs="text",
|
| 63 |
-
title="پیشنهادگر
|
| 64 |
)
|
| 65 |
|
| 66 |
iface.launch()
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
+
from argostranslate import package, translate
|
| 5 |
|
| 6 |
+
# تولید مدل انگلیسی برای موضوع پایاننامه
|
| 7 |
+
generator = pipeline("text-generation", model="tiiuae/falcon-rw-1b")
|
| 8 |
|
| 9 |
+
# گردان ترجمه انگلیسی به فارسی (argos-translate)
|
| 10 |
+
installed_languages = translate.get_installed_languages()
|
| 11 |
+
en_lang = list(filter(lambda x: x.code == "en", installed_languages))[0]
|
| 12 |
+
fa_lang = list(filter(lambda x: x.code == "fa", installed_languages))[0]
|
| 13 |
+
translator = en_lang.get_translation(fa_lang)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def generate_topics(field, major, keywords, audience, level):
|
| 16 |
prompt = f"""
|
| 17 |
+
Suggest 3 academic thesis topics based on the following information:
|
| 18 |
+
Field: {field}
|
| 19 |
+
Specialization: {major}
|
| 20 |
+
Keywords: {keywords}
|
| 21 |
+
Target audience: {audience}
|
| 22 |
+
Level: {level}
|
| 23 |
"""
|
|
|
|
| 24 |
|
| 25 |
+
# generate English topics
|
| 26 |
+
english_output = generator(prompt, max_new_tokens=256)[0]['generated_text']
|
|
|
|
| 27 |
|
| 28 |
+
# translate to Persian
|
| 29 |
+
translated_output = translator.translate(english_output)
|
| 30 |
|
| 31 |
+
# add final message
|
| 32 |
+
final_output = translated_output.strip() + "\n\n📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:\n02188252497"
|
| 33 |
|
| 34 |
+
return final_output
|
| 35 |
|
| 36 |
iface = gr.Interface(
|
| 37 |
fn=generate_topics,
|
|
|
|
| 43 |
gr.Dropdown(choices=["کارشناسی ارشد", "دکتری"], label="مقطع")
|
| 44 |
],
|
| 45 |
outputs="text",
|
| 46 |
+
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین"
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|