Jacksonnavigator7 commited on
Commit
441bf14
·
verified ·
1 Parent(s): 2a902de

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load your model and processor (replace with your model’s Hugging Face ID or local path)
7
+ model_name = "your-username/your-bird-classifier" # e.g., "dennisjooo/Birds-Classifier-EfficientNetB2"
8
+ processor = AutoImageProcessor.from_pretrained(model_name)
9
+ model = AutoModelForImageClassification.from_pretrained(model_name)
10
+
11
+ # Prediction function
12
+ def classify_bird(image):
13
+ # Process the image
14
+ inputs = processor(image, return_tensors="pt")
15
+ with torch.no_grad():
16
+ outputs = model(**inputs).logits
17
+ # Get the predicted label
18
+ predicted_idx = outputs.argmax(-1).item()
19
+ label = model.config.id2label[predicted_idx]
20
+ return f"Predicted bird species: {label}"
21
+
22
+ # Create the Gradio interface
23
+ interface = gr.Interface(
24
+ fn=classify_bird,
25
+ inputs=gr.Image(type="pil", label="Upload a bird image"),
26
+ outputs=gr.Textbox(label="Prediction"),
27
+ title="Bird Species Classifier",
28
+ description="Upload an image of a bird to identify its species!"
29
+ )
30
+
31
+ # Launch the app
32
+ interface.launch()