adding model
Browse files
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
app.py
CHANGED
@@ -1,7 +1,40 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
|
6 |
+
# Load your model
|
7 |
+
with open("model.pkl", "rb") as f:
|
8 |
+
model = pickle.load(f)
|
9 |
+
|
10 |
+
# Preprocessing function
|
11 |
+
def preprocess_image(img: Image.Image):
|
12 |
+
# Resize and convert to a flat array (adjust according to your model's needs)
|
13 |
+
img = img.resize((64, 64)) # example size
|
14 |
+
img_array = np.array(img)
|
15 |
+
if img_array.ndim == 3 and img_array.shape[2] == 3:
|
16 |
+
img_array = img_array.mean(axis=2) # convert to grayscale if needed
|
17 |
+
img_flat = img_array.flatten()
|
18 |
+
return img_flat
|
19 |
+
|
20 |
+
# Prediction function
|
21 |
+
def predict(image):
|
22 |
+
try:
|
23 |
+
img_flat = preprocess_image(image)
|
24 |
+
prediction = model.predict([img_flat])[0]
|
25 |
+
return prediction
|
26 |
+
except Exception as e:
|
27 |
+
return f"Error: {str(e)}"
|
28 |
+
|
29 |
+
# Gradio interface
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=predict,
|
32 |
+
inputs=gr.Image(type="pil"),
|
33 |
+
outputs="text",
|
34 |
+
title="Cat vs Dog Classifier",
|
35 |
+
description="Upload an image and the model will predict: cat, dog, or idk.",
|
36 |
+
)
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
iface.launch()
|
40 |
|
|
|
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e672faf54a8d818b779e978b129e64b4e2f6ef5d228d63dbbc60d7d137f7e34d
|
3 |
+
size 47068798
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.26.0
|
2 |
+
scikit-learn==1.4.2
|
3 |
+
pillow==10.3.0
|
4 |
+
numpy==1.26.4
|
5 |
+
|