Spaces:
Running
Running
classifier app
Browse files- .ipynb_checkpoints/classifier-checkpoint.ipynb +6 -0
- app.py +28 -4
- classifier.ipynb +54 -0
- data.zip +3 -0
.ipynb_checkpoints/classifier-checkpoint.ipynb
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [],
|
3 |
+
"metadata": {},
|
4 |
+
"nbformat": 4,
|
5 |
+
"nbformat_minor": 5
|
6 |
+
}
|
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
|
4 |
+
# Load a pre-trained image classification model
|
5 |
+
model = tf.keras.applications.MobileNetV2(weights='imagenet')
|
6 |
|
7 |
+
# Function to make predictions from an image
|
8 |
+
def classify_image(image):
|
9 |
+
# Resize the image to the required input size of the model
|
10 |
+
|
11 |
+
# Preprocess the image to match the model's requirements
|
12 |
+
|
13 |
+
# Make a prediction
|
14 |
+
|
15 |
+
# Decode the prediction and get the class name
|
16 |
+
class_name = np.random.randint(0,3)
|
17 |
+
classes = ["cat", "dog", "flower"]
|
18 |
+
return classes[class_name]
|
19 |
+
|
20 |
+
# Sample images for user to choose from
|
21 |
+
sample_images = ["cat.jpg", "dog.jpg", "flower.jpg"]
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=classify_image,
|
25 |
+
inputs=gr.inputs.Image(label="Select an image", type="file"),
|
26 |
+
outputs="text",
|
27 |
+
live=True,
|
28 |
+
examples=sample_images
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch()
|
classifier.ipynb
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "6afcec5d",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import fastbook\n",
|
11 |
+
"fastbook.setup_book()"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 2,
|
17 |
+
"id": "4e4f004b",
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"from fastai.vision.all import *"
|
22 |
+
]
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"cell_type": "code",
|
26 |
+
"execution_count": null,
|
27 |
+
"id": "a57b7136",
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": []
|
31 |
+
}
|
32 |
+
],
|
33 |
+
"metadata": {
|
34 |
+
"kernelspec": {
|
35 |
+
"display_name": "Python [conda env:hf]",
|
36 |
+
"language": "python",
|
37 |
+
"name": "conda-env-hf-py"
|
38 |
+
},
|
39 |
+
"language_info": {
|
40 |
+
"codemirror_mode": {
|
41 |
+
"name": "ipython",
|
42 |
+
"version": 3
|
43 |
+
},
|
44 |
+
"file_extension": ".py",
|
45 |
+
"mimetype": "text/x-python",
|
46 |
+
"name": "python",
|
47 |
+
"nbconvert_exporter": "python",
|
48 |
+
"pygments_lexer": "ipython3",
|
49 |
+
"version": "3.11.6"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"nbformat": 4,
|
53 |
+
"nbformat_minor": 5
|
54 |
+
}
|
data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c28ff00bdfb5ecb46c4cbab987a31b71543f1ac97d0832c52127a5338778ec3
|
3 |
+
size 1959428284
|