Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,19 @@ from deep_translator import GoogleTranslator
|
|
4 |
import torch
|
5 |
|
6 |
# مشخصات مدل
|
7 |
-
model_id = "google/gemma-
|
8 |
|
9 |
# بارگذاری مدل و توکنایزر
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
model = AutoModelForCausalLM.from_pretrained(
|
12 |
model_id,
|
13 |
torch_dtype=torch.bfloat16,
|
14 |
-
device_map="auto"
|
15 |
)
|
16 |
model.eval()
|
17 |
|
18 |
def generate_topics(field, major, keywords, audience, level):
|
19 |
-
# پرامپت
|
20 |
prompt = f"""[INST]Suggest 3 academic thesis topics based on the following information:
|
21 |
Field: {field}
|
22 |
Specialization: {major}
|
@@ -24,7 +24,7 @@ Keywords: {keywords}
|
|
24 |
Target audience: {audience}
|
25 |
Level: {level}[/INST]
|
26 |
"""
|
27 |
-
# تولید
|
28 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
29 |
with torch.no_grad():
|
30 |
outputs = model.generate(**inputs, max_new_tokens=256)
|
@@ -32,16 +32,15 @@ Level: {level}[/INST]
|
|
32 |
|
33 |
# ترجمه به فارسی
|
34 |
translated_output = GoogleTranslator(source='en', target='fa').translate(english_output)
|
|
|
35 |
|
36 |
-
# HTML راستچین
|
37 |
-
html_output =
|
38 |
-
|
39 |
-
|
40 |
-
<br><br>
|
41 |
-
|
42 |
-
|
43 |
-
</div>
|
44 |
-
"""
|
45 |
return html_output
|
46 |
|
47 |
# رابط Gradio
|
|
|
4 |
import torch
|
5 |
|
6 |
# مشخصات مدل
|
7 |
+
model_id = "google/gemma-3-4b-it" # یا "google/gemma-2-7b-it" بسته به نیاز شما
|
8 |
|
9 |
# بارگذاری مدل و توکنایزر
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
model = AutoModelForCausalLM.from_pretrained(
|
12 |
model_id,
|
13 |
torch_dtype=torch.bfloat16,
|
14 |
+
device_map="auto"
|
15 |
)
|
16 |
model.eval()
|
17 |
|
18 |
def generate_topics(field, major, keywords, audience, level):
|
19 |
+
# ساخت پرامپت
|
20 |
prompt = f"""[INST]Suggest 3 academic thesis topics based on the following information:
|
21 |
Field: {field}
|
22 |
Specialization: {major}
|
|
|
24 |
Target audience: {audience}
|
25 |
Level: {level}[/INST]
|
26 |
"""
|
27 |
+
# تولید خروجی
|
28 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
29 |
with torch.no_grad():
|
30 |
outputs = model.generate(**inputs, max_new_tokens=256)
|
|
|
32 |
|
33 |
# ترجمه به فارسی
|
34 |
translated_output = GoogleTranslator(source='en', target='fa').translate(english_output)
|
35 |
+
translated_output_html = translated_output.strip().replace("\n", "<br>")
|
36 |
|
37 |
+
# HTML راستچین
|
38 |
+
html_output = (
|
39 |
+
"<div dir='rtl' style='text-align: right; font-family: Tahoma, sans-serif; font-size: 16px; "
|
40 |
+
f"line-height: 1.8;'>{translated_output_html}"
|
41 |
+
"<br><br>📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:<br>"
|
42 |
+
"<strong>021-88252497</strong></div>"
|
43 |
+
)
|
|
|
|
|
44 |
return html_output
|
45 |
|
46 |
# رابط Gradio
|