Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer,
|
3 |
from deep_translator import GoogleTranslator
|
4 |
import torch
|
5 |
|
6 |
# مشخصات مدل
|
7 |
-
model_id = "google/gemma-3-4b-it"
|
8 |
|
9 |
# بارگذاری مدل و توکنایزر
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
-
model =
|
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}
|
23 |
Keywords: {keywords}
|
24 |
Target audience: {audience}
|
25 |
-
Level: {level}[/INST]
|
26 |
-
|
27 |
# تولید خروجی
|
28 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(
|
29 |
with torch.no_grad():
|
30 |
outputs = model.generate(**inputs, max_new_tokens=256)
|
31 |
english_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, GemmaForCausalLM
|
3 |
from deep_translator import GoogleTranslator
|
4 |
import torch
|
5 |
|
6 |
# مشخصات مدل
|
7 |
+
model_id = "google/gemma-3-4b-it"
|
8 |
|
9 |
# بارگذاری مدل و توکنایزر
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
+
model = GemmaForCausalLM.from_pretrained(
|
12 |
model_id,
|
13 |
+
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
|
14 |
device_map="auto"
|
15 |
)
|
16 |
model.eval()
|
17 |
|
18 |
def generate_topics(field, major, keywords, audience, level):
|
19 |
# ساخت پرامپت
|
20 |
+
prompt = f"""<bos>[INST]Suggest 3 academic thesis topics based on the following information:
|
21 |
Field: {field}
|
22 |
Specialization: {major}
|
23 |
Keywords: {keywords}
|
24 |
Target audience: {audience}
|
25 |
+
Level: {level}[/INST]"""
|
26 |
+
|
27 |
# تولید خروجی
|
28 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
29 |
with torch.no_grad():
|
30 |
outputs = model.generate(**inputs, max_new_tokens=256)
|
31 |
english_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|