Spaces:
Sleeping
Sleeping
save
Browse files- Dockerfile +3 -0
- src/streamlit_app.py +16 -8
Dockerfile
CHANGED
|
@@ -14,6 +14,9 @@ COPY src/ ./src/
|
|
| 14 |
|
| 15 |
RUN pip3 install -r requirements.txt
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
EXPOSE 8501
|
| 18 |
|
| 19 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
|
|
|
| 14 |
|
| 15 |
RUN pip3 install -r requirements.txt
|
| 16 |
|
| 17 |
+
# Create the outputs directory and set permissions
|
| 18 |
+
RUN mkdir -p outputs && chmod 777 outputs
|
| 19 |
+
|
| 20 |
EXPOSE 8501
|
| 21 |
|
| 22 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
src/streamlit_app.py
CHANGED
|
@@ -2,6 +2,8 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
from sklearn.model_selection import train_test_split
|
| 4 |
import pickle
|
|
|
|
|
|
|
| 5 |
|
| 6 |
from sklearn.metrics import accuracy_score
|
| 7 |
from sklearn.ensemble import RandomForestClassifier
|
|
@@ -43,12 +45,18 @@ y_pred = rfc.predict(x_test.values)
|
|
| 43 |
score = accuracy_score(y_pred, y_test)
|
| 44 |
st.write('Our accuracy score for this model is {}'.format(score))
|
| 45 |
|
| 46 |
-
st.subheader('Model Output to Pickle')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
output_pickle = open(outputfilename, 'wb')
|
| 53 |
-
pickle.dump(uniques, output_pickle)
|
| 54 |
-
output_pickle.close()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from sklearn.model_selection import train_test_split
|
| 4 |
import pickle
|
| 5 |
+
import os
|
| 6 |
+
import pickle
|
| 7 |
|
| 8 |
from sklearn.metrics import accuracy_score
|
| 9 |
from sklearn.ensemble import RandomForestClassifier
|
|
|
|
| 45 |
score = accuracy_score(y_pred, y_test)
|
| 46 |
st.write('Our accuracy score for this model is {}'.format(score))
|
| 47 |
|
| 48 |
+
st.subheader('Save the Model Output to Pickle')
|
| 49 |
+
|
| 50 |
+
# Create output directory if it doesn't exist
|
| 51 |
+
output_dir = "outputs"
|
| 52 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 53 |
+
|
| 54 |
+
# Save the model
|
| 55 |
+
model_filename = os.path.join(output_dir, "random_forest_penguin.pickle")
|
| 56 |
+
with open(model_filename, "wb") as rf_pickle:
|
| 57 |
+
pickle.dump(rfc, rf_pickle)
|
| 58 |
|
| 59 |
+
# Save the uniques or other data
|
| 60 |
+
uniques_filename = os.path.join(output_dir, "uniques_data.pickle")
|
| 61 |
+
with open(uniques_filename, "wb") as output_pickle:
|
| 62 |
+
pickle.dump(uniques, output_pickle)
|
|
|
|
|
|
|
|
|