Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +27 -4
src/streamlit_app.py
CHANGED
@@ -115,6 +115,20 @@ def build_cnn_model(input_length, num_classes=3, num_words=10000, embedding_dim=
|
|
115 |
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
|
116 |
return model
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
#----------------------------------------------------------------------------------------------------
|
120 |
# Sidebar
|
@@ -168,17 +182,26 @@ elif choose == "CNN":
|
|
168 |
|
169 |
# Upload file
|
170 |
training_file = st.file_uploader("Upload Data Training (.txt)", accept_multiple_files=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
real_files = st.file_uploader("Upload Data Real (.txt)", accept_multiple_files=True)
|
172 |
|
|
|
|
|
|
|
173 |
# Parameter model
|
174 |
epochs = st.number_input("Jumlah Epoch", min_value=1, value=2000)
|
175 |
batch_size = st.number_input("Ukuran Batch", min_value=1, value=32)
|
176 |
-
|
177 |
if st.button("Proses Data"):
|
178 |
-
if
|
179 |
# Memproses data training
|
180 |
try:
|
181 |
-
data_train, labels_train, bandwidth_train = load_data(
|
182 |
if len(data_train) == 0:
|
183 |
st.error("Data training tidak valid atau kosong!")
|
184 |
st.stop()
|
@@ -263,7 +286,7 @@ elif choose == "CNN":
|
|
263 |
|
264 |
# Memproses data real
|
265 |
data_real, labels_real, bandwidth_real = [], [], []
|
266 |
-
for file in
|
267 |
d, lbl, bw = load_data(file)
|
268 |
data_real.extend(d)
|
269 |
labels_real.extend(lbl)
|
|
|
115 |
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
|
116 |
return model
|
117 |
|
118 |
+
def extract_text_from_file(file):
|
119 |
+
|
120 |
+
'''Extract text from uploaded file'''
|
121 |
+
|
122 |
+
# read text file
|
123 |
+
if file.type == "text/plain":
|
124 |
+
# To convert to a string based IO:
|
125 |
+
stringio = StringIO(file.getvalue().decode("cp1252"))
|
126 |
+
|
127 |
+
# To read file as string:
|
128 |
+
file_text = stringio.read()
|
129 |
+
|
130 |
+
return file_text, None
|
131 |
+
|
132 |
|
133 |
#----------------------------------------------------------------------------------------------------
|
134 |
# Sidebar
|
|
|
182 |
|
183 |
# Upload file
|
184 |
training_file = st.file_uploader("Upload Data Training (.txt)", accept_multiple_files=True)
|
185 |
+
|
186 |
+
if uploaded_file is not None:
|
187 |
+
text_training_file, title_traning = extract_text_from_file(training_file)
|
188 |
+
|
189 |
+
# file_1 = st.sidebar.file_uploader('Upload Data Training (.txt)', type=['txt'],accept_multiple_files=False, key='file_1', label_visibility='hidden')
|
190 |
+
|
191 |
real_files = st.file_uploader("Upload Data Real (.txt)", accept_multiple_files=True)
|
192 |
|
193 |
+
if real_files is not None:
|
194 |
+
text_real_files, title_real = extract_text_from_file(real_files)
|
195 |
+
|
196 |
# Parameter model
|
197 |
epochs = st.number_input("Jumlah Epoch", min_value=1, value=2000)
|
198 |
batch_size = st.number_input("Ukuran Batch", min_value=1, value=32)
|
199 |
+
|
200 |
if st.button("Proses Data"):
|
201 |
+
if text_training_file and text_real_files:
|
202 |
# Memproses data training
|
203 |
try:
|
204 |
+
data_train, labels_train, bandwidth_train = load_data(text_training_file)
|
205 |
if len(data_train) == 0:
|
206 |
st.error("Data training tidak valid atau kosong!")
|
207 |
st.stop()
|
|
|
286 |
|
287 |
# Memproses data real
|
288 |
data_real, labels_real, bandwidth_real = [], [], []
|
289 |
+
for file in text_real_files:
|
290 |
d, lbl, bw = load_data(file)
|
291 |
data_real.extend(d)
|
292 |
labels_real.extend(lbl)
|