Spaces:
Runtime error
Runtime error
Nassima Oukali
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,6 @@ model_name = "ahmed792002/Finetuning_MBart_English_Arabic_Translation"
|
|
6 |
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
7 |
tokenizer = MBart50TokenizerFast.from_pretrained(model_name)
|
8 |
|
9 |
-
# Set source and target languages
|
10 |
-
tokenizer.src_lang = "en_XX" # Source language
|
11 |
-
tokenizer.tgt_lang = "ar_AR" # Target language
|
12 |
-
|
13 |
# Streamlit App
|
14 |
st.title("English to Arabic Translation")
|
15 |
st.write("Enter text in English to translate it to Arabic:")
|
@@ -19,18 +15,16 @@ english_text = st.text_area("Enter English Text")
|
|
19 |
|
20 |
# Translate the text when the button is clicked
|
21 |
if st.button("Translate"):
|
22 |
-
if english_text
|
23 |
# Tokenize the input
|
24 |
-
inputs = tokenizer(english_text, return_tensors="pt", padding=True
|
25 |
-
|
26 |
-
|
27 |
# Generate translation
|
28 |
translated = model.generate(**inputs)
|
29 |
-
|
30 |
-
|
31 |
# Decode the translated text
|
32 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
33 |
-
|
34 |
# Display the translated text
|
35 |
st.write(f"Translated text: {translated_text}")
|
36 |
else:
|
|
|
6 |
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
7 |
tokenizer = MBart50TokenizerFast.from_pretrained(model_name)
|
8 |
|
|
|
|
|
|
|
|
|
9 |
# Streamlit App
|
10 |
st.title("English to Arabic Translation")
|
11 |
st.write("Enter text in English to translate it to Arabic:")
|
|
|
15 |
|
16 |
# Translate the text when the button is clicked
|
17 |
if st.button("Translate"):
|
18 |
+
if english_text:
|
19 |
# Tokenize the input
|
20 |
+
inputs = tokenizer(english_text, return_tensors="pt", padding=True)
|
21 |
+
|
|
|
22 |
# Generate translation
|
23 |
translated = model.generate(**inputs)
|
24 |
+
|
|
|
25 |
# Decode the translated text
|
26 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
27 |
+
|
28 |
# Display the translated text
|
29 |
st.write(f"Translated text: {translated_text}")
|
30 |
else:
|