Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
st.title("English to Levantine Arabic")
|
7 |
|
8 |
-
num_translations = st.sidebar.selectbox("Number of Translations:", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=
|
9 |
input_text = st.text_input("Enter English text:")
|
10 |
|
11 |
if input_text:
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
for
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
dialects = {"Palestinian/Jordanian": "P", "Syrian": "S", "Lebanese": "L", "Egyptian": "E"}
|
6 |
+
|
7 |
+
pipeline = pipeline(task="translation", model="guymorlan/English2Dialect")
|
8 |
|
9 |
st.title("English to Levantine Arabic")
|
10 |
|
11 |
+
num_translations = st.sidebar.selectbox("Number of Translations Per Dialect:", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=0)
|
12 |
input_text = st.text_input("Enter English text:")
|
13 |
|
14 |
if input_text:
|
15 |
+
inputs = [f"{val} {input_text}" for val in dialects.values()]
|
16 |
+
result = pipeline(inputs, max_length=1024, num_return_sequences=num_translations, num_beams=max(num_translations, 5))
|
17 |
+
#df = pd.DataFrame({"Dialect": [x for x in dialects.keys()],
|
18 |
+
# "Translation": [x["translation_text"] for x in result]})
|
19 |
+
|
20 |
+
for i in range(len(result)):
|
21 |
+
st.markdown(f"<div style='font-size:24px'><b>{list(dialects.keys())[i]}:</b></div>", unsafe_allow_html=True)
|
22 |
+
if num_translations > 1:
|
23 |
+
for j in range(num_translations):
|
24 |
+
st.markdown(f"<div style='font-size:24px; text-align:right; direction:rtl;'>{result[i][j]['translation_text']}</div>", unsafe_allow_html=True)
|
25 |
+
else:
|
26 |
+
st.markdown(f"<div style='font-size:24px; text-align:right; direction:rtl;'>{result[i]['translation_text']}</div>", unsafe_allow_html=True)
|
27 |
+
st.markdown("<br>", unsafe_allow_html=True)
|