Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import MarianMTModel, MarianTokenizer
|
3 |
-
from PIL import Image
|
4 |
|
5 |
# Define available languages with MarianMT models
|
6 |
LANGUAGES = {
|
@@ -14,24 +13,9 @@ LANGUAGES = {
|
|
14 |
'Russian': 'ru',
|
15 |
'Italian': 'it',
|
16 |
'Portuguese': 'pt',
|
|
|
17 |
}
|
18 |
|
19 |
-
# Load a background image for the app
|
20 |
-
def add_bg_image(image_path):
|
21 |
-
with open(image_path, "rb") as f:
|
22 |
-
data = f.read()
|
23 |
-
st.markdown(
|
24 |
-
f"""
|
25 |
-
<style>
|
26 |
-
.stApp {{
|
27 |
-
background-image: url(data:image/{"png"};base64,{data.encode("base64").decode()});
|
28 |
-
background-size: cover;
|
29 |
-
}}
|
30 |
-
</style>
|
31 |
-
""",
|
32 |
-
unsafe_allow_html=True
|
33 |
-
)
|
34 |
-
|
35 |
# Function to load the model based on the selected language
|
36 |
@st.cache_resource
|
37 |
def load_model(src_lang='en', tgt_lang='es'):
|
@@ -47,9 +31,6 @@ def translate_text(model, tokenizer, text):
|
|
47 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
48 |
return translated_text
|
49 |
|
50 |
-
# Load the background image
|
51 |
-
add_bg_image("path_to_your_image.png") # You need to provide your image
|
52 |
-
|
53 |
# Streamlit app layout
|
54 |
st.markdown("<h1 style='text-align: center; color: #4B9CD3;'>π Multilingual Translator π</h1>", unsafe_allow_html=True)
|
55 |
st.markdown("<p style='text-align: center; color: #333; font-size: 18px;'>Translate English text into multiple languages</p>", unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import MarianMTModel, MarianTokenizer
|
|
|
3 |
|
4 |
# Define available languages with MarianMT models
|
5 |
LANGUAGES = {
|
|
|
13 |
'Russian': 'ru',
|
14 |
'Italian': 'it',
|
15 |
'Portuguese': 'pt',
|
16 |
+
# Add more languages if needed
|
17 |
}
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# Function to load the model based on the selected language
|
20 |
@st.cache_resource
|
21 |
def load_model(src_lang='en', tgt_lang='es'):
|
|
|
31 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
32 |
return translated_text
|
33 |
|
|
|
|
|
|
|
34 |
# Streamlit app layout
|
35 |
st.markdown("<h1 style='text-align: center; color: #4B9CD3;'>π Multilingual Translator π</h1>", unsafe_allow_html=True)
|
36 |
st.markdown("<p style='text-align: center; color: #333; font-size: 18px;'>Translate English text into multiple languages</p>", unsafe_allow_html=True)
|