Spaces:
No application file
No application file
Upload 3 files
Browse files- requirements.txt +30 -0
- run.py +45 -0
- svm_model.pkl +3 -0
requirements.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
blinker==1.7.0
|
| 2 |
+
click==8.1.7
|
| 3 |
+
contourpy==1.2.1
|
| 4 |
+
cycler==0.12.1
|
| 5 |
+
Flask==3.0.3
|
| 6 |
+
fonttools==4.51.0
|
| 7 |
+
imageio==2.34.0
|
| 8 |
+
itsdangerous==2.1.2
|
| 9 |
+
Jinja2==3.1.3
|
| 10 |
+
joblib==1.4.0
|
| 11 |
+
kiwisolver==1.4.5
|
| 12 |
+
lazy_loader==0.4
|
| 13 |
+
MarkupSafe==2.1.5
|
| 14 |
+
matplotlib==3.8.4
|
| 15 |
+
networkx==3.3
|
| 16 |
+
numpy==1.26.4
|
| 17 |
+
packaging==24.0
|
| 18 |
+
pandas==2.2.1
|
| 19 |
+
pillow==10.3.0
|
| 20 |
+
pyparsing==3.1.2
|
| 21 |
+
python-dateutil==2.9.0.post0
|
| 22 |
+
pytz==2024.1
|
| 23 |
+
scikit-image==0.22.0
|
| 24 |
+
scikit-learn==1.4.1.post1
|
| 25 |
+
scipy==1.13.0
|
| 26 |
+
six==1.16.0
|
| 27 |
+
threadpoolctl==3.4.0
|
| 28 |
+
tifffile==2024.2.12
|
| 29 |
+
tzdata==2024.1
|
| 30 |
+
Werkzeug==3.0.2
|
run.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import os
|
| 3 |
+
from skimage.transform import resize
|
| 4 |
+
from skimage.io import imread
|
| 5 |
+
import numpy as np
|
| 6 |
+
from sklearn import svm
|
| 7 |
+
from sklearn.model_selection import GridSearchCV
|
| 8 |
+
import joblib
|
| 9 |
+
|
| 10 |
+
app = Flask(__name__)
|
| 11 |
+
|
| 12 |
+
# Load the trained model
|
| 13 |
+
model = joblib.load('svm_nidek.pkl')
|
| 14 |
+
|
| 15 |
+
Categories = ['cats', 'dogs']
|
| 16 |
+
|
| 17 |
+
@app.route('/classify_image', methods=['POST'])
|
| 18 |
+
def classify_image():
|
| 19 |
+
# Receive the image file from the request
|
| 20 |
+
image_file = request.files['image']
|
| 21 |
+
# Save the image to a temporary location
|
| 22 |
+
temp_path = 'temp.jpg'
|
| 23 |
+
image_file.save(temp_path)
|
| 24 |
+
|
| 25 |
+
# Load and preprocess the image
|
| 26 |
+
img_array = imread(temp_path)
|
| 27 |
+
img_resized = resize(img_array, (50, 50, 3))
|
| 28 |
+
img_flattened = img_resized.flatten()
|
| 29 |
+
img_flattened = np.expand_dims(img_flattened, axis=0)
|
| 30 |
+
|
| 31 |
+
# Predict the class probabilities
|
| 32 |
+
probabilities = model.predict_proba(img_flattened)[0]
|
| 33 |
+
# Get the predicted class
|
| 34 |
+
predicted_class = Categories[np.argmax(probabilities)]
|
| 35 |
+
# Get the probability of the predicted class
|
| 36 |
+
confidence = probabilities[np.argmax(probabilities)]
|
| 37 |
+
|
| 38 |
+
# Delete the temporary image file
|
| 39 |
+
os.remove(temp_path)
|
| 40 |
+
|
| 41 |
+
# Return the result to the Flutter application
|
| 42 |
+
return jsonify({'predicted_class': predicted_class, 'confidence': confidence})
|
| 43 |
+
|
| 44 |
+
if __name__ == '__main__':
|
| 45 |
+
app.run(debug=True, host='0.0.0.0')
|
svm_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5484efe9e12996dd67e4933ff05ee8221821b4ad1c9059b03eb2fe11b42dea6e
|
| 3 |
+
size 4806131
|