Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +5 -29
src/streamlit_app.py
CHANGED
|
@@ -115,21 +115,6 @@ 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 |
-
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
|
| 135 |
#----------------------------------------------------------------------------------------------------
|
|
@@ -181,27 +166,18 @@ elif choose == "CNN":
|
|
| 181 |
st.write("Aplikasi ini menggunakan model CNN untuk mengklasifikasikan data bandwidth menjadi Fake, Genuine, atau No Heavy Activity")
|
| 182 |
|
| 183 |
# Upload file
|
| 184 |
-
training_file = st.file_uploader("Upload Data Training (.txt)", accept_multiple_files=True)
|
| 185 |
-
|
| 186 |
-
if training_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
|
| 202 |
# Memproses data training
|
| 203 |
try:
|
| 204 |
-
data_train, labels_train, bandwidth_train = load_data(
|
| 205 |
if len(data_train) == 0:
|
| 206 |
st.error("Data training tidak valid atau kosong!")
|
| 207 |
st.stop()
|
|
@@ -286,7 +262,7 @@ elif choose == "CNN":
|
|
| 286 |
|
| 287 |
# Memproses data real
|
| 288 |
data_real, labels_real, bandwidth_real = [], [], []
|
| 289 |
-
for file in
|
| 290 |
d, lbl, bw = load_data(file)
|
| 291 |
data_real.extend(d)
|
| 292 |
labels_real.extend(lbl)
|
|
|
|
| 115 |
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
|
| 116 |
return model
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
#----------------------------------------------------------------------------------------------------
|
| 119 |
# Sidebar
|
| 120 |
#----------------------------------------------------------------------------------------------------
|
|
|
|
| 166 |
st.write("Aplikasi ini menggunakan model CNN untuk mengklasifikasikan data bandwidth menjadi Fake, Genuine, atau No Heavy Activity")
|
| 167 |
|
| 168 |
# Upload file
|
| 169 |
+
training_file = st.file_uploader("Upload Data Training (.txt)", accept_multiple_files=True, label_visibility='hidden')
|
| 170 |
+
real_files = st.file_uploader("Upload Data Real (.txt)", accept_multiple_files=True, label_visibility='hidden')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
# Parameter model
|
| 173 |
epochs = st.number_input("Jumlah Epoch", min_value=1, value=2000)
|
| 174 |
batch_size = st.number_input("Ukuran Batch", min_value=1, value=32)
|
| 175 |
|
| 176 |
if st.button("Proses Data"):
|
| 177 |
+
if training_file and real_files:
|
| 178 |
# Memproses data training
|
| 179 |
try:
|
| 180 |
+
data_train, labels_train, bandwidth_train = load_data(training_file)
|
| 181 |
if len(data_train) == 0:
|
| 182 |
st.error("Data training tidak valid atau kosong!")
|
| 183 |
st.stop()
|
|
|
|
| 262 |
|
| 263 |
# Memproses data real
|
| 264 |
data_real, labels_real, bandwidth_real = [], [], []
|
| 265 |
+
for file in real_files:
|
| 266 |
d, lbl, bw = load_data(file)
|
| 267 |
data_real.extend(d)
|
| 268 |
labels_real.extend(lbl)
|