Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load translation pipeline (placeholder - you can load your fine-tuned model here)
|
5 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hi")
|
6 |
+
|
7 |
+
# Set Streamlit page config
|
8 |
+
st.set_page_config(page_title="Translator", layout="wide")
|
9 |
+
|
10 |
+
# UI Design starts here
|
11 |
+
st.markdown("""
|
12 |
+
<style>
|
13 |
+
.big-font {
|
14 |
+
font-size:25px !important;
|
15 |
+
font-weight: bold;
|
16 |
+
}
|
17 |
+
.tab-style {
|
18 |
+
display: flex;
|
19 |
+
gap: 20px;
|
20 |
+
font-size:18px;
|
21 |
+
}
|
22 |
+
.tab-style div {
|
23 |
+
cursor: pointer;
|
24 |
+
}
|
25 |
+
.output-box {
|
26 |
+
background-color: #f9f9f9;
|
27 |
+
padding: 20px;
|
28 |
+
border-radius: 10px;
|
29 |
+
min-height: 300px;
|
30 |
+
font-size: 22px;
|
31 |
+
}
|
32 |
+
.copy-button {
|
33 |
+
margin-top: 10px;
|
34 |
+
}
|
35 |
+
</style>
|
36 |
+
""", unsafe_allow_html=True)
|
37 |
+
|
38 |
+
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)
|
39 |
+
st.markdown("---")
|
40 |
+
|
41 |
+
# Create two columns
|
42 |
+
col1, col2 = st.columns(2)
|
43 |
+
|
44 |
+
with col1:
|
45 |
+
st.markdown('<div class="big-font">hi how are you</div>', unsafe_allow_html=True)
|
46 |
+
user_input = st.text_area("", "hi how are you", height=250)
|
47 |
+
translate_button = st.button("Translate", use_container_width=True)
|
48 |
+
|
49 |
+
with col2:
|
50 |
+
if translate_button and user_input:
|
51 |
+
# Translate text
|
52 |
+
translated_text = translator(user_input, max_length=400)[0]['translation_text']
|
53 |
+
else:
|
54 |
+
translated_text = ""
|
55 |
+
|
56 |
+
st.markdown('<div class="output-box">' + (translated_text if translated_text else "") + '</div>', unsafe_allow_html=True)
|
57 |
+
|
58 |
+
if translated_text:
|
59 |
+
st.button("Copy", use_container_width=True)
|
60 |
+
st.button("Paraphrase", use_container_width=True)
|