guymorlan commited on
Commit
ebb3fe8
1 Parent(s): 7e7155f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -1,18 +1,27 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
3
 
4
- pipeline = pipeline(task="translation", model="guymorlan/English2Shami")
 
 
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=2)
9
  input_text = st.text_input("Enter English text:")
10
 
11
  if input_text:
12
- result = pipeline(input_text, max_length=1024, num_return_sequences=num_translations, num_beams=max(num_translations, 5))
13
- # st.markdown("<div style='font-size:24px; text-align:right; direction:rtl;'>", unsafe_allow_html=True)
14
- outs = list(set([x["translation_text"] for x in result]))
15
- for i in range(len(outs)):
16
- st.markdown(f"<div style='font-size:24px; text-align:right; direction:rtl;'>{outs[i]}</div>", unsafe_allow_html=True)
17
- st.markdown("<br>", unsafe_allow_html=True)
18
- #st.markdown("</div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
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)