Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,60 +2,55 @@ import streamlit as st
|
|
2 |
import transformers
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
# Load translation pipeline (
|
6 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hi")
|
7 |
|
8 |
-
#
|
9 |
st.set_page_config(page_title="Translator", layout="wide")
|
10 |
|
11 |
-
#
|
|
|
|
|
|
|
12 |
st.markdown("""
|
13 |
<style>
|
14 |
-
.big-font {
|
15 |
-
|
16 |
-
|
17 |
-
}
|
18 |
-
.
|
19 |
-
display: flex;
|
20 |
-
gap: 20px;
|
21 |
-
font-size:18px;
|
22 |
-
}
|
23 |
-
.tab-style div {
|
24 |
-
cursor: pointer;
|
25 |
-
}
|
26 |
-
.output-box {
|
27 |
-
background-color: #f9f9f9;
|
28 |
-
padding: 20px;
|
29 |
-
border-radius: 10px;
|
30 |
-
min-height: 300px;
|
31 |
-
font-size: 22px;
|
32 |
-
}
|
33 |
-
.copy-button {
|
34 |
-
margin-top: 10px;
|
35 |
-
}
|
36 |
</style>
|
37 |
""", unsafe_allow_html=True)
|
38 |
|
39 |
-
st.markdown('<div class="tab-style"><div>English - Detected</div><div>Hindi</div><div>English</div><div>Spanish</div><div>All (50)</div></div>', unsafe_allow_html=True)
|
40 |
-
st.markdown("---")
|
41 |
-
|
42 |
# Create two columns
|
43 |
col1, col2 = st.columns(2)
|
44 |
|
45 |
with col1:
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
user_input = st.text_area("", "hi how are you", height=250)
|
|
|
|
|
48 |
translate_button = st.button("Translate", use_container_width=True)
|
49 |
|
50 |
with col2:
|
|
|
|
|
|
|
51 |
if translate_button and user_input:
|
52 |
-
#
|
|
|
53 |
translated_text = translator(user_input, max_length=400)[0]['translation_text']
|
54 |
else:
|
55 |
translated_text = ""
|
56 |
-
|
|
|
57 |
st.markdown('<div class="output-box">' + (translated_text if translated_text else "") + '</div>', unsafe_allow_html=True)
|
58 |
|
|
|
59 |
if translated_text:
|
60 |
st.button("Copy", use_container_width=True)
|
61 |
st.button("Paraphrase", use_container_width=True)
|
|
|
2 |
import transformers
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
# Load translation pipeline (use your fine-tuned model here later)
|
6 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hi")
|
7 |
|
8 |
+
# Streamlit page config
|
9 |
st.set_page_config(page_title="Translator", layout="wide")
|
10 |
|
11 |
+
# Language options
|
12 |
+
languages = ["English", "Hindi", "Spanish", "Odia", "Telugu"]
|
13 |
+
|
14 |
+
# UI starts here
|
15 |
st.markdown("""
|
16 |
<style>
|
17 |
+
.big-font { font-size:25px !important; font-weight: bold; }
|
18 |
+
.tab-style { display: flex; gap: 20px; font-size:18px; }
|
19 |
+
.tab-style div { cursor: pointer; }
|
20 |
+
.output-box { background-color: #f9f9f9; padding: 20px; border-radius: 10px; min-height: 300px; font-size: 22px; }
|
21 |
+
.copy-button { margin-top: 10px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
</style>
|
23 |
""", unsafe_allow_html=True)
|
24 |
|
|
|
|
|
|
|
25 |
# Create two columns
|
26 |
col1, col2 = st.columns(2)
|
27 |
|
28 |
with col1:
|
29 |
+
# Detected Language Dropdown
|
30 |
+
source_lang = st.selectbox("Detected Language", languages, index=0)
|
31 |
+
|
32 |
+
# Text input
|
33 |
+
st.markdown('<div class="big-font">Enter your text:</div>', unsafe_allow_html=True)
|
34 |
user_input = st.text_area("", "hi how are you", height=250)
|
35 |
+
|
36 |
+
# Translate Button
|
37 |
translate_button = st.button("Translate", use_container_width=True)
|
38 |
|
39 |
with col2:
|
40 |
+
# Target Language Dropdown
|
41 |
+
target_lang = st.selectbox("Translate To", languages, index=1)
|
42 |
+
|
43 |
if translate_button and user_input:
|
44 |
+
# Right now, not actually changing based on languages selected
|
45 |
+
# You can later map different models based on selected languages
|
46 |
translated_text = translator(user_input, max_length=400)[0]['translation_text']
|
47 |
else:
|
48 |
translated_text = ""
|
49 |
+
|
50 |
+
# Show translated text
|
51 |
st.markdown('<div class="output-box">' + (translated_text if translated_text else "") + '</div>', unsafe_allow_html=True)
|
52 |
|
53 |
+
# Copy and Paraphrase Buttons
|
54 |
if translated_text:
|
55 |
st.button("Copy", use_container_width=True)
|
56 |
st.button("Paraphrase", use_container_width=True)
|