Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -72,6 +72,9 @@ def preprocessing(input_text, tokenizer):
|
|
72 |
# truncation=True
|
73 |
# )
|
74 |
|
|
|
|
|
|
|
75 |
# initialising the Softmax function
|
76 |
soft = Softmax()
|
77 |
|
@@ -102,44 +105,54 @@ def load_model(model_name):
|
|
102 |
return pipeline("text-classification", model=model_name, return_all_scores=True)
|
103 |
|
104 |
|
105 |
-
page_element="""
|
106 |
<style>
|
107 |
-
[data-testid="stAppViewContainer"]{
|
108 |
background-image: url("https://w7.pngwing.com/pngs/980/181/png-transparent-flat-white-background-abstract-flat-white-thumbnail.png");
|
109 |
background-size: cover;
|
110 |
}
|
111 |
-
[data-testid="stHeader"]{
|
112 |
-
background-color: rgba(0,0,0,0);
|
113 |
}
|
114 |
-
[data-testid="stToolbar"]{
|
115 |
right: 2rem;
|
116 |
background-image: url("https://img.freepik.com/premium-vector/burger-icon-isolated-illustration_92753-2926.jpg?w=2000");
|
117 |
background-size: cover;
|
118 |
}
|
|
|
|
|
|
|
119 |
</style>
|
120 |
"""
|
|
|
|
|
121 |
st.markdown(page_element, unsafe_allow_html=True)
|
122 |
|
|
|
123 |
# File upload section
|
124 |
st.title("Moral Values Detection App")
|
125 |
st.markdown("Authors: [Vjosa Preniqi](https://scholar.google.com/citations?user=CLZ3LL4AAAAJ&hl=en) and [Iacopo Ghinassi](https://scholar.google.com/citations?user=ANXW5EAAAAAJ&hl=en).")
|
126 |
st.header("Introduction", divider = "red")
|
127 |
-
st.markdown("""This app implements the models described in the papers [MoralBERT: A Fine-Tuned Language Model for Capturing Moral Values in Social Discussions](https://dl.acm.org/doi/abs/10.1145/3677525.3678694) and [Automatic Detection of Moral Values in Music Lyrics](https://arxiv.org/abs/2407.18787). With this app, you can automatically predict and label text or music lyrics with 10 moral categories. To use it, upload a CSV file with a single column named "text" (for regular text) or "lyrics" (for music lyrics). Each row should have the text or lyric you want to analyse. Keep in mind, the process may take up to 10 seconds per entry, and the models work best with social media content and music lyrics. Once the analysis is done, the app will show a table with the predicted probabilities for each moral value. You can download this table using the provided button. Note that some moral values might have consistently low probabilities. If that's the case, you may need to use a lower threshold to identify them—check the original papers for more details.""")
|
128 |
-
model_type = st.radio("
|
129 |
|
130 |
# Warning if model type is not selected before file upload
|
131 |
if not model_type:
|
132 |
-
st.warning("Please pick the
|
133 |
|
134 |
# File upload section
|
135 |
-
st.write(f"Upload a CSV file with a column named 'text' or 'lyrics'
|
136 |
|
137 |
-
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
138 |
|
139 |
|
140 |
if uploaded_file is not None:
|
141 |
# Read CSV
|
142 |
-
|
|
|
|
|
|
|
|
|
143 |
|
144 |
# Validation: Check if the correct column exists based on the selected model type
|
145 |
expected_column = 'lyrics' if model_type == 'lyrics' else 'text'
|
|
|
72 |
# truncation=True
|
73 |
# )
|
74 |
|
75 |
+
def convert_excel_to_csv(file):
|
76 |
+
return pd.read_excel(file)
|
77 |
+
|
78 |
# initialising the Softmax function
|
79 |
soft = Softmax()
|
80 |
|
|
|
105 |
return pipeline("text-classification", model=model_name, return_all_scores=True)
|
106 |
|
107 |
|
108 |
+
page_element = """
|
109 |
<style>
|
110 |
+
[data-testid="stAppViewContainer"] {
|
111 |
background-image: url("https://w7.pngwing.com/pngs/980/181/png-transparent-flat-white-background-abstract-flat-white-thumbnail.png");
|
112 |
background-size: cover;
|
113 |
}
|
114 |
+
[data-testid="stHeader"] {
|
115 |
+
background-color: rgba(0, 0, 0, 0);
|
116 |
}
|
117 |
+
[data-testid="stToolbar"] {
|
118 |
right: 2rem;
|
119 |
background-image: url("https://img.freepik.com/premium-vector/burger-icon-isolated-illustration_92753-2926.jpg?w=2000");
|
120 |
background-size: cover;
|
121 |
}
|
122 |
+
body {
|
123 |
+
color: black !important; /* Set font color to black */
|
124 |
+
}
|
125 |
</style>
|
126 |
"""
|
127 |
+
|
128 |
+
# Add the style to your Streamlit app
|
129 |
st.markdown(page_element, unsafe_allow_html=True)
|
130 |
|
131 |
+
|
132 |
# File upload section
|
133 |
st.title("Moral Values Detection App")
|
134 |
st.markdown("Authors: [Vjosa Preniqi](https://scholar.google.com/citations?user=CLZ3LL4AAAAJ&hl=en) and [Iacopo Ghinassi](https://scholar.google.com/citations?user=ANXW5EAAAAAJ&hl=en).")
|
135 |
st.header("Introduction", divider = "red")
|
136 |
+
st.markdown("""This app implements the models described in the papers [MoralBERT: A Fine-Tuned Language Model for Capturing Moral Values in Social Discussions](https://dl.acm.org/doi/abs/10.1145/3677525.3678694) and [Automatic Detection of Moral Values in Music Lyrics](https://arxiv.org/abs/2407.18787). With this app, you can automatically predict and label text or music lyrics with 10 moral categories. To use it, upload a CSV or Excel file with a single column named "text" (for regular text) or "lyrics" (for music lyrics). Each row should have the text or lyric you want to analyse. Keep in mind, the process may take up to 10 seconds per entry, and the models work best with social media content and music lyrics. Once the analysis is done, the app will show a table with the predicted probabilities for each moral value. You can download this table using the provided button. Note that some moral values might have consistently low probabilities. If that's the case, you may need to use a lower threshold to identify them—check the original papers for more details.""")
|
137 |
+
model_type = st.radio("Select the content type to choose the appropriate prediction model", ('text', 'lyrics'))
|
138 |
|
139 |
# Warning if model type is not selected before file upload
|
140 |
if not model_type:
|
141 |
+
st.warning("Please pick the content type for prediction first.")
|
142 |
|
143 |
# File upload section
|
144 |
+
st.write(f"Upload a CSV or Excel file with a column named 'text' or 'lyrics' based on the model type you chose.")
|
145 |
|
146 |
+
uploaded_file = st.file_uploader("Choose a CSV or Excel file", type=["csv", "xlsx"])
|
147 |
|
148 |
|
149 |
if uploaded_file is not None:
|
150 |
# Read CSV
|
151 |
+
file_extension = uploaded_file.name.split('.')[-1].lower()
|
152 |
+
if file_extension == "csv":
|
153 |
+
df = pd.read_csv(uploaded_file)
|
154 |
+
elif file_extension == "xlsx":
|
155 |
+
df = convert_excel_to_csv(uploaded_file)
|
156 |
|
157 |
# Validation: Check if the correct column exists based on the selected model type
|
158 |
expected_column = 'lyrics' if model_type == 'lyrics' else 'text'
|