Spaces:
Build error
Build error
Upload 4 files
Browse files- Dockerfile +17 -0
- requirements.txt +101 -0
- rf_model.pkl +3 -0
- server.py +51 -0
Dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python 3.10 as the base image
|
| 2 |
+
FROM python:3.10
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy all files to the container
|
| 8 |
+
COPY . /app
|
| 9 |
+
|
| 10 |
+
# Install required packages
|
| 11 |
+
RUN pip install -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Expose port 7860
|
| 14 |
+
EXPOSE 7860
|
| 15 |
+
|
| 16 |
+
# Run the Flask app
|
| 17 |
+
CMD ["python", "server.py"]
|
requirements.txt
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
absl-py==2.1.0
|
| 2 |
+
alembic==1.13.3
|
| 3 |
+
asttokens==2.4.1
|
| 4 |
+
astunparse==1.6.3
|
| 5 |
+
blinker==1.8.2
|
| 6 |
+
certifi==2024.8.30
|
| 7 |
+
charset-normalizer==3.3.2
|
| 8 |
+
Choco==1.0.5
|
| 9 |
+
click==8.1.7
|
| 10 |
+
cloudpickle==3.1.0
|
| 11 |
+
colorama==0.4.6
|
| 12 |
+
colorlog==6.8.2
|
| 13 |
+
comm==0.2.2
|
| 14 |
+
contourpy==1.3.0
|
| 15 |
+
cycler==0.12.1
|
| 16 |
+
debugpy==1.8.6
|
| 17 |
+
decorator==5.1.1
|
| 18 |
+
et_xmlfile==2.0.0
|
| 19 |
+
executing==2.1.0
|
| 20 |
+
Flask==3.0.3
|
| 21 |
+
Flask-Cors==5.0.0
|
| 22 |
+
flatbuffers==24.3.25
|
| 23 |
+
fonttools==4.54.1
|
| 24 |
+
gast==0.6.0
|
| 25 |
+
google-pasta==0.2.0
|
| 26 |
+
gower==0.1.2
|
| 27 |
+
greenlet==3.1.1
|
| 28 |
+
grpcio==1.66.2
|
| 29 |
+
h5py==3.12.1
|
| 30 |
+
idna==3.10
|
| 31 |
+
ipykernel==6.29.5
|
| 32 |
+
ipython==8.28.0
|
| 33 |
+
itsdangerous==2.2.0
|
| 34 |
+
jedi==0.19.1
|
| 35 |
+
Jinja2==3.1.4
|
| 36 |
+
joblib==1.4.2
|
| 37 |
+
jupyter_client==8.6.3
|
| 38 |
+
jupyter_core==5.7.2
|
| 39 |
+
keras==3.6.0
|
| 40 |
+
kiwisolver==1.4.7
|
| 41 |
+
libclang==18.1.1
|
| 42 |
+
llvmlite==0.43.0
|
| 43 |
+
Mako==1.3.5
|
| 44 |
+
Markdown==3.7
|
| 45 |
+
markdown-it-py==3.0.0
|
| 46 |
+
MarkupSafe==2.1.5
|
| 47 |
+
matplotlib==3.9.2
|
| 48 |
+
matplotlib-inline==0.1.7
|
| 49 |
+
mdurl==0.1.2
|
| 50 |
+
ml-dtypes==0.4.1
|
| 51 |
+
namex==0.0.8
|
| 52 |
+
nest-asyncio==1.6.0
|
| 53 |
+
numba==0.60.0
|
| 54 |
+
numpy==1.26.4
|
| 55 |
+
openpyxl==3.1.5
|
| 56 |
+
opt_einsum==3.4.0
|
| 57 |
+
optree==0.13.0
|
| 58 |
+
optuna==4.0.0
|
| 59 |
+
packaging==24.1
|
| 60 |
+
pandas==2.2.3
|
| 61 |
+
parso==0.8.4
|
| 62 |
+
pillow==10.4.0
|
| 63 |
+
platformdirs==4.3.6
|
| 64 |
+
prompt_toolkit==3.0.48
|
| 65 |
+
protobuf==4.25.5
|
| 66 |
+
psutil==6.0.0
|
| 67 |
+
pure_eval==0.2.3
|
| 68 |
+
Pygments==2.18.0
|
| 69 |
+
pyparsing==3.1.4
|
| 70 |
+
python-dateutil==2.9.0.post0
|
| 71 |
+
pytz==2024.2
|
| 72 |
+
PyYAML==6.0.2
|
| 73 |
+
pyzmq==26.2.0
|
| 74 |
+
requests==2.32.3
|
| 75 |
+
rich==13.9.2
|
| 76 |
+
scikit-learn==1.5.2
|
| 77 |
+
scipy==1.14.1
|
| 78 |
+
seaborn==0.13.2
|
| 79 |
+
setuptools==75.1.0
|
| 80 |
+
shap==0.46.0
|
| 81 |
+
six==1.16.0
|
| 82 |
+
slicer==0.0.8
|
| 83 |
+
SQLAlchemy==2.0.36
|
| 84 |
+
stack-data==0.6.3
|
| 85 |
+
tensorboard==2.17.1
|
| 86 |
+
tensorboard-data-server==0.7.2
|
| 87 |
+
tensorflow==2.17.0
|
| 88 |
+
tensorflow-intel==2.17.0
|
| 89 |
+
termcolor==2.4.0
|
| 90 |
+
threadpoolctl==3.5.0
|
| 91 |
+
tornado==6.4.1
|
| 92 |
+
tqdm==4.66.5
|
| 93 |
+
traitlets==5.14.3
|
| 94 |
+
typing_extensions==4.12.2
|
| 95 |
+
tzdata==2024.2
|
| 96 |
+
urllib3==2.2.3
|
| 97 |
+
wcwidth==0.2.13
|
| 98 |
+
Werkzeug==3.0.4
|
| 99 |
+
wheel==0.44.0
|
| 100 |
+
wrapt==1.16.0
|
| 101 |
+
xgboost==2.1.1
|
rf_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:41b44ae921d87879451237b3195675f3c475cbd1fd904c734c12f16bd0a0be1f
|
| 3 |
+
size 1935849
|
server.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
# Load your pre-trained model
|
| 8 |
+
model = joblib.load('rf_model.pkl')
|
| 9 |
+
threshold = 0.7032966204148201
|
| 10 |
+
|
| 11 |
+
@app.route('/')
|
| 12 |
+
def home():
|
| 13 |
+
return render_template('index.html')
|
| 14 |
+
|
| 15 |
+
@app.route('/predict', methods=['POST'])
|
| 16 |
+
def predict():
|
| 17 |
+
try:
|
| 18 |
+
# Extract values from the form
|
| 19 |
+
features = [
|
| 20 |
+
float(request.form.get('AppendixDiameter')),
|
| 21 |
+
float(request.form.get('ReboundTenderness')),
|
| 22 |
+
float(request.form.get('CoughingPain')),
|
| 23 |
+
float(request.form.get('FreeFluids')),
|
| 24 |
+
float(request.form.get('MigratoryPain')),
|
| 25 |
+
float(request.form.get('BodyTemp')),
|
| 26 |
+
float(request.form.get('KetonesInUrine')),
|
| 27 |
+
float(request.form.get('Nausea')),
|
| 28 |
+
float(request.form.get('WBCCount')),
|
| 29 |
+
float(request.form.get('NeutrophilPerc')),
|
| 30 |
+
float(request.form.get('CRPEntry')),
|
| 31 |
+
float(request.form.get('Peritonitis'))
|
| 32 |
+
]
|
| 33 |
+
print("features",features)
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return render_template('index.html', prediction_text="Error in input: " + str(e))
|
| 36 |
+
|
| 37 |
+
# Create a DataFrame with proper column names
|
| 38 |
+
columns = ['AppendixDiameter', 'ReboundTenderness', 'CoughingPain', 'FreeFluids', 'MigratoryPain',
|
| 39 |
+
'BodyTemp', 'KetonesInUrine', 'Nausea', 'WBCCount', 'NeutrophilPerc', 'CRPEntry', 'Peritonitis']
|
| 40 |
+
data = pd.DataFrame([features], columns=columns)
|
| 41 |
+
|
| 42 |
+
# Get the predicted probability and apply your threshold
|
| 43 |
+
pred_prob = model.predict_proba(data)[0][1]
|
| 44 |
+
prediction = 1 if pred_prob >= threshold else 0
|
| 45 |
+
|
| 46 |
+
result = "Appendicitis" if prediction == 1 else "No Appendicitis"
|
| 47 |
+
|
| 48 |
+
return render_template('index.html', prediction_text=f"Prediction: {result}")
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
app.run(host="0.0.0.0", port=7860)
|