Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 2 |
+
import torch
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# Загрузка модели
|
| 7 |
+
model = AutoModelForImageClassification.from_pretrained("jeemsterri/fish_classification")
|
| 8 |
+
processor = AutoImageProcessor.from_pretrained("jeemsterri/fish_classification")
|
| 9 |
+
|
| 10 |
+
# Предсказание
|
| 11 |
+
def classify_image(image):
|
| 12 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 13 |
+
outputs = model(**inputs)
|
| 14 |
+
probs = torch.nn.functional.softmax(outputs.logits, dim=1)
|
| 15 |
+
confidence, predicted_class = torch.max(probs, dim=1)
|
| 16 |
+
label = model.config.id2label[predicted_class.item()]
|
| 17 |
+
return {label: float(confidence)}
|
| 18 |
+
|
| 19 |
+
gr.Interface(fn=classify_image,
|
| 20 |
+
inputs=gr.Image(type="pil"),
|
| 21 |
+
outputs=gr.Label(num_top_classes=3),
|
| 22 |
+
title="Fish Species Classifier",
|
| 23 |
+
description="Upload a fish image and get the predicted species.").launch()
|