Spaces:
Sleeping
Sleeping
Commit
·
ab810fc
1
Parent(s):
46c2c8d
Adding template upload content & upload slank
Browse files- app.py +34 -24
- assets/contoh template data content.xlsx +0 -0
- assets/contoh template data slank.txt +0 -0
app.py
CHANGED
@@ -77,6 +77,31 @@ def get_image_download_link(image_path):
|
|
77 |
href = f'<a href="data:file/png;base64,{b64}" download="{image_path}">Download {image_path}</a>'
|
78 |
return href
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
def combined_analysis(text, slank_formal_df):
|
82 |
texts = text.split('\n')
|
@@ -126,8 +151,6 @@ def combined_analysis(text, slank_formal_df):
|
|
126 |
|
127 |
return df
|
128 |
|
129 |
-
|
130 |
-
|
131 |
def process_file(file, slank_formal_df):
|
132 |
if file.name.endswith('.xlsx'):
|
133 |
df = pd.read_excel(file)
|
@@ -190,31 +213,14 @@ def process_file(file, slank_formal_df):
|
|
190 |
|
191 |
return df
|
192 |
|
193 |
-
|
194 |
-
def analyze_sentiment(text):
|
195 |
-
result = sentiment_pipe(text)[0]
|
196 |
-
return result['label'].lower(), result['score']
|
197 |
-
|
198 |
-
def analyze_emotion(text):
|
199 |
-
result = emotion_pipe(text)[0]
|
200 |
-
return result['label'].lower(), result['score']
|
201 |
-
|
202 |
-
def get_download_link(df, filename):
|
203 |
-
csv = df.to_csv(index=False)
|
204 |
-
b64 = base64.b64encode(csv.encode()).decode()
|
205 |
-
href = f'<a href="data:file/csv;base64,{b64}" download="{filename}.csv">Download CSV</a>'
|
206 |
-
return href
|
207 |
-
|
208 |
-
def get_word_freq_download_link(word_freq_df):
|
209 |
-
csv = word_freq_df.to_csv(index=True)
|
210 |
-
b64 = base64.b64encode(csv.encode()).decode()
|
211 |
-
href = f'<a href="data:file/csv;base64,{b64}" download="word_frequency.csv">Download Word Frequency CSV</a>'
|
212 |
-
return href
|
213 |
-
|
214 |
def main():
|
215 |
st.title("Aplikasi Analisis Sentimen dan Prediksi Emosi")
|
216 |
|
217 |
-
|
|
|
|
|
|
|
|
|
218 |
if slank_file is not None:
|
219 |
df_slank_formal = load_slank_formal(slank_file)
|
220 |
if df_slank_formal is None:
|
@@ -234,6 +240,10 @@ def main():
|
|
234 |
st.markdown(get_download_link(df, "analisis_sentimen_emosi"), unsafe_allow_html=True)
|
235 |
|
236 |
elif menu == "Import dari File":
|
|
|
|
|
|
|
|
|
237 |
uploaded_file = st.file_uploader("Upload file CSV atau XLSX", type=["csv", "xlsx"])
|
238 |
if uploaded_file is not None:
|
239 |
df = process_file(uploaded_file, df_slank_formal)
|
|
|
77 |
href = f'<a href="data:file/png;base64,{b64}" download="{image_path}">Download {image_path}</a>'
|
78 |
return href
|
79 |
|
80 |
+
def analyze_sentiment(text):
|
81 |
+
result = sentiment_pipe(text)[0]
|
82 |
+
return result['label'].lower(), result['score']
|
83 |
+
|
84 |
+
def analyze_emotion(text):
|
85 |
+
result = emotion_pipe(text)[0]
|
86 |
+
return result['label'].lower(), result['score']
|
87 |
+
|
88 |
+
def get_download_link(df, filename):
|
89 |
+
csv = df.to_csv(index=False)
|
90 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
91 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="{filename}.csv">Download CSV</a>'
|
92 |
+
return href
|
93 |
+
|
94 |
+
def get_word_freq_download_link(word_freq_df):
|
95 |
+
csv = word_freq_df.to_csv(index=True)
|
96 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
97 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="word_frequency.csv">Download Word Frequency CSV</a>'
|
98 |
+
return href
|
99 |
+
|
100 |
+
def get_example_download_link(file_path, link_text):
|
101 |
+
with open(file_path, "rb") as file:
|
102 |
+
b64 = base64.b64encode(file.read()).decode()
|
103 |
+
return f'<a href="data:file/txt;base64,{b64}" download="{os.path.basename(file_path)}">{link_text}</a>'
|
104 |
+
|
105 |
|
106 |
def combined_analysis(text, slank_formal_df):
|
107 |
texts = text.split('\n')
|
|
|
151 |
|
152 |
return df
|
153 |
|
|
|
|
|
154 |
def process_file(file, slank_formal_df):
|
155 |
if file.name.endswith('.xlsx'):
|
156 |
df = pd.read_excel(file)
|
|
|
213 |
|
214 |
return df
|
215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
def main():
|
217 |
st.title("Aplikasi Analisis Sentimen dan Prediksi Emosi")
|
218 |
|
219 |
+
# Add download link for example slank template
|
220 |
+
slank_template_path = "assets\contoh template data slank.txt"
|
221 |
+
st.markdown(get_example_download_link(slank_template_path, "Download Contoh Template Data Slank (TXT)"), unsafe_allow_html=True)
|
222 |
+
|
223 |
+
slank_file = st.file_uploader("Upload file slank dengan baris pertama Slank;Formal (TXT)", type=["txt"])
|
224 |
if slank_file is not None:
|
225 |
df_slank_formal = load_slank_formal(slank_file)
|
226 |
if df_slank_formal is None:
|
|
|
240 |
st.markdown(get_download_link(df, "analisis_sentimen_emosi"), unsafe_allow_html=True)
|
241 |
|
242 |
elif menu == "Import dari File":
|
243 |
+
# Add download link for example content template
|
244 |
+
content_template_path = "assets\contoh template data content.xlsx"
|
245 |
+
st.markdown(get_example_download_link(content_template_path, "Download Contoh Template Data Content (XLSX)"), unsafe_allow_html=True)
|
246 |
+
|
247 |
uploaded_file = st.file_uploader("Upload file CSV atau XLSX", type=["csv", "xlsx"])
|
248 |
if uploaded_file is not None:
|
249 |
df = process_file(uploaded_file, df_slank_formal)
|
assets/contoh template data content.xlsx
ADDED
Binary file (10.1 kB). View file
|
|
assets/contoh template data slank.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|