Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import torch
|
4 |
|
@@ -14,24 +13,12 @@ tokenizer = AutoTokenizer.from_pretrained("universitytehran/PersianMind-v1.0")
|
|
14 |
|
15 |
# Conversation template
|
16 |
TEMPLATE = "{context}\nYou: {prompt}\nPersianMind: "
|
17 |
-
CONTEXT = "
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
if st.button("Get Response"):
|
27 |
-
if prompt.strip():
|
28 |
-
with st.spinner("Generating response..."):
|
29 |
-
model_input = TEMPLATE.format(context=CONTEXT, prompt=prompt)
|
30 |
-
input_tokens = tokenizer(model_input, return_tensors="pt").to(device)
|
31 |
-
generate_ids = model.generate(**input_tokens, max_new_tokens=512, do_sample=False, repetition_penalty=1.1)
|
32 |
-
model_output = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
33 |
-
response = model_output[len(model_input):]
|
34 |
-
|
35 |
-
st.text_area("PersianMind's Response:", response, height=200)
|
36 |
-
else:
|
37 |
-
st.warning("Please enter a text.")
|
|
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
import torch
|
3 |
|
|
|
13 |
|
14 |
# Conversation template
|
15 |
TEMPLATE = "{context}\nYou: {prompt}\nPersianMind: "
|
16 |
+
CONTEXT = "به انگلیسی ترجمه کن"
|
17 |
+
prompt = "به انگلیسی ترجمه کن: وزیر امور خارجه ایران در نشست خبری اعلام کرد که مذاکرات هستهای به دلیل اختلافات اساسی درباره اجرای تعهدات متوقف شده است. او تأکید کرد که ایران همچنان به دنبال یک توافق عادلانه و متوازن است، اما طرفهای مقابل باید از سیاستهای دوگانه خود دست بردارند"
|
18 |
|
19 |
+
model_input = TEMPLATE.format(context=CONTEXT, prompt=prompt)
|
20 |
+
input_tokens = tokenizer(model_input, return_tensors="pt").to(device)
|
21 |
+
generate_ids = model.generate(**input_tokens, max_new_tokens=512, do_sample=False, repetition_penalty=1.1)
|
22 |
+
model_output = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
23 |
+
response = model_output[len(model_input):]
|
24 |
+
print(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|