Spaces:
Sleeping
Sleeping
Dhahlan2000
commited on
Commit
•
b549a09
1
Parent(s):
609cc40
Update app.py
Browse files
app.py
CHANGED
@@ -24,9 +24,6 @@ translator = pipeline('translation', model=trans_model, tokenizer=eng_trans_toke
|
|
24 |
# Initialize translation pipelines
|
25 |
pipe = pipeline("translation", model="thilina/mt5-sinhalese-english")
|
26 |
|
27 |
-
trans_model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
|
28 |
-
eng_trans_tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_lang="en_XX")
|
29 |
-
|
30 |
sin_trans_model = AutoModelForSeq2SeqLM.from_pretrained("thilina/mt5-sinhalese-english")
|
31 |
si_trans_tokenizer = AutoTokenizer.from_pretrained("thilina/mt5-sinhalese-english")
|
32 |
|
@@ -102,12 +99,13 @@ def transliterate_to_sinhala(text):
|
|
102 |
latin_text = transliterate.process(source_script, target_script, text)
|
103 |
return latin_text
|
104 |
|
105 |
-
|
106 |
-
"
|
107 |
-
|
108 |
-
|
|
|
109 |
)
|
110 |
-
|
111 |
|
112 |
|
113 |
def conversation_predict(prompt):
|
@@ -115,24 +113,22 @@ def conversation_predict(prompt):
|
|
115 |
{"role": "system", "content": "You are a helpful assistant."},
|
116 |
{"role": "user", "content": prompt}
|
117 |
]
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
)
|
123 |
-
model_inputs = ai_tokenizer([text], return_tensors="pt").to(device)
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
]
|
132 |
|
133 |
-
|
134 |
|
135 |
-
return
|
136 |
|
137 |
def ai_predicted(user_input):
|
138 |
user_input = translate_Singlish_to_sinhala(user_input)
|
|
|
24 |
# Initialize translation pipelines
|
25 |
pipe = pipeline("translation", model="thilina/mt5-sinhalese-english")
|
26 |
|
|
|
|
|
|
|
27 |
sin_trans_model = AutoModelForSeq2SeqLM.from_pretrained("thilina/mt5-sinhalese-english")
|
28 |
si_trans_tokenizer = AutoTokenizer.from_pretrained("thilina/mt5-sinhalese-english")
|
29 |
|
|
|
99 |
latin_text = transliterate.process(source_script, target_script, text)
|
100 |
return latin_text
|
101 |
|
102 |
+
model = AutoModelForCausalLM.from_pretrained(
|
103 |
+
"microsoft/Phi-3-mini-4k-instruct",
|
104 |
+
device_map="cuda",
|
105 |
+
torch_dtype="auto",
|
106 |
+
trust_remote_code=True,
|
107 |
)
|
108 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
109 |
|
110 |
|
111 |
def conversation_predict(prompt):
|
|
|
113 |
{"role": "system", "content": "You are a helpful assistant."},
|
114 |
{"role": "user", "content": prompt}
|
115 |
]
|
116 |
+
pipe = pipeline(
|
117 |
+
"text-generation",
|
118 |
+
model=model,
|
119 |
+
tokenizer=tokenizer,
|
120 |
)
|
|
|
121 |
|
122 |
+
generation_args = {
|
123 |
+
"max_new_tokens": 500,
|
124 |
+
"return_full_text": False,
|
125 |
+
"temperature": 0.0,
|
126 |
+
"do_sample": False,
|
127 |
+
}
|
|
|
128 |
|
129 |
+
output = pipe(messages, **generation_args)
|
130 |
|
131 |
+
return output[0]['generated_text']
|
132 |
|
133 |
def ai_predicted(user_input):
|
134 |
user_input = translate_Singlish_to_sinhala(user_input)
|