Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,13 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
-
from
|
5 |
|
6 |
-
# تولید
|
7 |
-
|
8 |
|
9 |
-
#
|
10 |
-
|
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"""
|
@@ -22,15 +19,10 @@ Target audience: {audience}
|
|
22 |
Level: {level}
|
23 |
"""
|
24 |
|
25 |
-
|
26 |
-
|
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(
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
+
from googletrans import Translator
|
5 |
|
6 |
+
# تولید موضوع به انگلیسی
|
7 |
+
text_generator = pipeline("text-generation", model="tiiuae/falcon-rw-1b")
|
8 |
|
9 |
+
# ترجمه به فارسی با googletrans
|
10 |
+
translator = Translator()
|
|
|
|
|
|
|
11 |
|
12 |
def generate_topics(field, major, keywords, audience, level):
|
13 |
prompt = f"""
|
|
|
19 |
Level: {level}
|
20 |
"""
|
21 |
|
22 |
+
english_output = text_generator(prompt, max_new_tokens=256)[0]['generated_text']
|
23 |
+
translated_output = translator.translate(english_output, src='en', dest='fa').text
|
24 |
|
|
|
|
|
|
|
|
|
25 |
final_output = translated_output.strip() + "\n\n📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:\n02188252497"
|
|
|
26 |
return final_output
|
27 |
|
28 |
iface = gr.Interface(
|