Spaces:
Sleeping
Sleeping
Create app.py (#1)
Browse files- Create app.py (41169d1aa920bfa06970e5af458f7e72efbb3cfb)
Co-authored-by: OUILY Hamed Joseph <[email protected]>
app.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Tagba Translator"""
|
2 |
+
import streamlit as st
|
3 |
+
import requests
|
4 |
+
|
5 |
+
api_url = "https://31d7-196-13-207-151.ngrok-free.app/"
|
6 |
+
|
7 |
+
|
8 |
+
if 'source_lang' not in st.session_state:
|
9 |
+
st.session_state.source_lang = 'Français'
|
10 |
+
if 'target_lang' not in st.session_state:
|
11 |
+
st.session_state.target_lang = 'Tagba'
|
12 |
+
|
13 |
+
st.markdown(
|
14 |
+
"""
|
15 |
+
<style>
|
16 |
+
.stApp {
|
17 |
+
background-color: #003366;
|
18 |
+
margin: 0;
|
19 |
+
padding: 0;
|
20 |
+
display: flex;
|
21 |
+
justify-content: center;
|
22 |
+
align-items: center;
|
23 |
+
height: 100vh;
|
24 |
+
}
|
25 |
+
.col-container {
|
26 |
+
font-weight: bold;
|
27 |
+
font-size: 25px;
|
28 |
+
font-family: calibri(corps);
|
29 |
+
color: antiquewhite;
|
30 |
+
border: 2px solid antiquewhite;
|
31 |
+
border-radius: 50px;
|
32 |
+
display: inline-flex;
|
33 |
+
justify-content: center;
|
34 |
+
text-align: center;
|
35 |
+
padding: 2px 4px;
|
36 |
+
margin-top: 30px;
|
37 |
+
margin-left: 90px;
|
38 |
+
}
|
39 |
+
.stColumns > div {
|
40 |
+
border: 2px solid #000;
|
41 |
+
}
|
42 |
+
.title {
|
43 |
+
text-align: center;
|
44 |
+
font-size: 48px;
|
45 |
+
font-weight: bold;
|
46 |
+
margin-bottom: 10px;
|
47 |
+
font-family: 'Brush Script MT', cursive;
|
48 |
+
font-weight: bold;
|
49 |
+
color: #FFFFFF;
|
50 |
+
text-align: center;
|
51 |
+
letter-spacing: 1px;
|
52 |
+
position: relative;
|
53 |
+
}
|
54 |
+
.title::after {
|
55 |
+
content: "";
|
56 |
+
position: absolute;
|
57 |
+
bottom: -5px;
|
58 |
+
left: 10%;
|
59 |
+
width: 80%;
|
60 |
+
height: 2px;
|
61 |
+
background-color: #FFFFFF;
|
62 |
+
}
|
63 |
+
.footer {
|
64 |
+
color: antiquewhite;
|
65 |
+
}
|
66 |
+
.block-container {
|
67 |
+
background: rgba(255, 255, 255, 0.3);
|
68 |
+
min-width: 500px;
|
69 |
+
min-height: 600px;
|
70 |
+
padding: 30px;
|
71 |
+
box-sizing: border-box;
|
72 |
+
border-radius: 10px;
|
73 |
+
box-shadow: 3px 6px 40px rgba(0, 0, 0, 0.1);
|
74 |
+
display: flex;
|
75 |
+
flex-direction: column;
|
76 |
+
justify-content: flex-start;
|
77 |
+
align-items: center;
|
78 |
+
heigh: 100%;
|
79 |
+
position: absolute;
|
80 |
+
}
|
81 |
+
.stButton>button {
|
82 |
+
display: block;
|
83 |
+
margin:: 0 auto;
|
84 |
+
position: absolute;
|
85 |
+
margin-top: 20px;
|
86 |
+
}
|
87 |
+
</style>
|
88 |
+
""",
|
89 |
+
unsafe_allow_html=True
|
90 |
+
)
|
91 |
+
|
92 |
+
st.markdown('<h1 class="title">Tagba Translator</h1>', unsafe_allow_html=True)
|
93 |
+
|
94 |
+
col1, col_swap, col2 = st.columns([1, 0.05, 1], gap="small")
|
95 |
+
|
96 |
+
with col_swap:
|
97 |
+
st.write("")
|
98 |
+
swap = st.button("⇄")
|
99 |
+
|
100 |
+
if swap:
|
101 |
+
st.session_state.source_lang, st.session_state.target_lang = st.session_state.target_lang, st.session_state.source_lang
|
102 |
+
|
103 |
+
if "translation" not in st.session_state:
|
104 |
+
st.session_state.translation = "Traduction"
|
105 |
+
|
106 |
+
with col1:
|
107 |
+
st.markdown('<h3 class="col-container">'+st.session_state.source_lang+'</h3>', unsafe_allow_html=True)
|
108 |
+
text_to_translate = st.text_area(
|
109 |
+
label=" ",
|
110 |
+
height=200,
|
111 |
+
placeholder="Entrez un texte ici"
|
112 |
+
)
|
113 |
+
|
114 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
115 |
+
if st.button("Traduire"):
|
116 |
+
if text_to_translate:
|
117 |
+
try:
|
118 |
+
response = requests.post('https://31d7-196-13-207-151.ngrok-free.app/translate/', json={"text": text_to_translate, "lang": st.session_state.target_lang}, timeout=1000)
|
119 |
+
if response.status_code == 200:
|
120 |
+
translation = response.json()["translation"]
|
121 |
+
st.session_state.translation = translation
|
122 |
+
else:
|
123 |
+
st.error("Erreur lors de la traduction.")
|
124 |
+
response.raise_for_status()
|
125 |
+
except requests.exceptions.RequestException as e:
|
126 |
+
st.error("Erreur lors de la traduction.")
|
127 |
+
print(e)
|
128 |
+
else:
|
129 |
+
st.warning("Veuillez entrer du texte à traduire.")
|
130 |
+
|
131 |
+
with col2:
|
132 |
+
st.markdown('<h3 class="col-container style="margin-top: 10px; margin-bottom: 10px;">'+st.session_state.target_lang+'</h3>', unsafe_allow_html=True)
|
133 |
+
st.text_area(
|
134 |
+
label=" ",
|
135 |
+
value=st.session_state.translation,
|
136 |
+
height=200
|
137 |
+
)
|
138 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
139 |
+
|