Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
import nltk | |
nltk.download('punkt') | |
from nltk.tokenize import sent_tokenize | |
# Load pipeline for translation | |
st.set_page_config(page_title="English to Vietnamese Translator", page_icon="🌐", layout="wide") | |
st.title("🌐 English to Vietnamese Translator") | |
model_checkpoint = "hHoai/hoaih" | |
translator = pipeline("translation", model=model_checkpoint) | |
# Create two columns for input and output | |
col1, col2 = st.columns(2) | |
# Add CSS for styling | |
st.markdown(""" | |
<style> | |
.reportview-container { | |
flex-direction: row; | |
justify-content: center; | |
align-items: center; | |
} | |
.sidebar .sidebar-content { | |
background-image: linear-gradient(#2e7bcf, #2e7bcf); | |
color: white; | |
} | |
.css-1d391kg { | |
font-size: 20px; | |
} | |
.css-1aumxhk { | |
background-color: #f0f2f6; | |
padding: 20px; | |
border-radius: 10px; | |
} | |
.css-1aumxhk:hover { | |
background-color: #e8e9eb; | |
} | |
.css-1aumxhk:focus { | |
outline: none; | |
border: 2px solid #2e7bcf; | |
} | |
.css-12oz5g7 { | |
font-size: 24px; | |
font-weight: bold; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
with col1: | |
st.header("Input") | |
input_text = st.text_area("Enter English text here maximum 2 line:", height=300, placeholder="Type your text here...") | |
with col2: | |
st.header("Output") | |
if input_text: | |
sentences = sent_tokenize(input_text) | |
translation_text = "" | |
for sentence in sentences: | |
translation = translator(sentence) | |
translation_text += translation[0]["translation_text"] + " " | |
st.text_area("Translated text will appear here:", value=translation_text.strip(), height=300, disabled=True) | |
else: | |
st.text_area("Translated text will appear here:", value="", height=300, disabled=True) | |
# Add footer | |
st.markdown(""" | |
<div style="text-align: center; margin-top: 50px;"> | |
<p>Developed with ❤️ by [hHoai]</p> | |
</div> | |
""", unsafe_allow_html=True) | |