Spaces:
Running
Running
Track the streamlit application file
Browse files- app.py +68 -0
- constants.py +3 -0
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Hint: this cheatsheet is magic! https://cheat-sheet.streamlit.app/
|
2 |
+
|
3 |
+
import constants
|
4 |
+
import pandas as pd
|
5 |
+
import streamlit as st
|
6 |
+
from transformers import BertForSequenceClassification, AutoTokenizer
|
7 |
+
|
8 |
+
|
9 |
+
@st.cache_data
|
10 |
+
def convert_df(df):
|
11 |
+
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
12 |
+
return df.to_csv(index=None).encode("utf-8")
|
13 |
+
|
14 |
+
|
15 |
+
def compute_ALDi(inputs):
|
16 |
+
return 0.5
|
17 |
+
|
18 |
+
|
19 |
+
input_type = st.sidebar.radio(
|
20 |
+
"Select the input type:", [constants.CHOICE_FILE, constants.CHOICE_TEXT]
|
21 |
+
)
|
22 |
+
|
23 |
+
st.title(constants.TITLE)
|
24 |
+
|
25 |
+
if input_type == constants.CHOICE_TEXT:
|
26 |
+
sent = st.text_input("Arabic Sentence:", placeholder="Enter an Arabic sentence.")
|
27 |
+
|
28 |
+
# TODO: Check if this is needed!
|
29 |
+
st.button("Submit")
|
30 |
+
|
31 |
+
if sent:
|
32 |
+
ALDi_score = compute_ALDi(sent)
|
33 |
+
st.write(ALDi_score)
|
34 |
+
|
35 |
+
else:
|
36 |
+
file = st.file_uploader("Upload a file", type=["txt"])
|
37 |
+
if file is not None:
|
38 |
+
df = pd.read_csv(file, sep="\t", header=None)
|
39 |
+
df.columns = ["Sentence"]
|
40 |
+
|
41 |
+
# TODO: Run the model
|
42 |
+
df["ALDi"] = df["Sentence"].apply(lambda s: compute_ALDi(s))
|
43 |
+
|
44 |
+
# A horizontal rule
|
45 |
+
st.markdown("""---""")
|
46 |
+
|
47 |
+
col1, col2 = st.columns([2, 3])
|
48 |
+
|
49 |
+
with col1:
|
50 |
+
# Add a download button
|
51 |
+
csv = convert_df(df)
|
52 |
+
|
53 |
+
st.download_button(
|
54 |
+
label=":file_folder: Download predictions as CSV",
|
55 |
+
data=csv,
|
56 |
+
file_name="ALDi_scores.csv",
|
57 |
+
mime="text/csv",
|
58 |
+
)
|
59 |
+
|
60 |
+
# Display the output
|
61 |
+
st.dataframe(
|
62 |
+
df,
|
63 |
+
hide_index=True,
|
64 |
+
)
|
65 |
+
|
66 |
+
with col2:
|
67 |
+
# TODO: Add the visualization
|
68 |
+
st.image("https://static.streamlit.io/examples/dog.jpg")
|
constants.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
CHOICE_TEXT = "Input Text"
|
2 |
+
CHOICE_FILE = "Upload File"
|
3 |
+
TITLE = "ALDi: Arabic Level of Dialectness"
|