Spaces:
Sleeping
Sleeping
Mazhar Mohsin
commited on
Commit
·
851fba8
1
Parent(s):
b235dda
Initial commit
Browse files- .gitignore +1 -0
- app.py +26 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv
|
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize the image classification pipeline
|
5 |
+
classifier = pipeline("image-classification")
|
6 |
+
# Alternatively you can define what model should the pipeline use, sometimes it requires that you login with your token
|
7 |
+
#classifier = pipeline("image-classification", model="microsoft/resnet-50")
|
8 |
+
|
9 |
+
#print(classifier.model)
|
10 |
+
|
11 |
+
def classify_image(image):
|
12 |
+
results = classifier(image)
|
13 |
+
# Get the top prediction
|
14 |
+
top_result = results[0]
|
15 |
+
label = top_result['label']
|
16 |
+
score = top_result['score']
|
17 |
+
return f"Label: {label}, Confidence: {score:.2f}"
|
18 |
+
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=classify_image,
|
21 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
22 |
+
outputs=gr.Textbox(label="Prediction"),
|
23 |
+
title="Image Classifier"
|
24 |
+
)
|
25 |
+
|
26 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
torchvision
|