Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,31 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
# Model
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def predict(image, more=False):
|
| 14 |
image = image.convert("RGB")
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
probA = torch.nn.functional.softmax(logitsA, dim=0)
|
| 26 |
-
topA_idx = torch.argmax(probA).item()
|
| 27 |
-
topA_score = round((probA[topA_idx] * 100).item(), 2)
|
| 28 |
-
|
| 29 |
-
labelA = modelA.config.id2label.get(topA_idx, f"Class {topA_idx}")
|
| 30 |
-
return f"{labelA} – %{topA_score}", ""
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
demo = gr.Interface(
|
| 34 |
fn=predict,
|
| 35 |
-
inputs=
|
| 36 |
-
outputs=
|
| 37 |
-
title="Bitki Tanıma
|
| 38 |
-
description="
|
|
|
|
| 39 |
)
|
| 40 |
-
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 2 |
from PIL import Image
|
| 3 |
+
import gradio as gr
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
# Model yükle
|
| 7 |
+
processor = AutoImageProcessor.from_pretrained("umutbozdag/plant-identity")
|
| 8 |
+
model = AutoModelForImageClassification.from_pretrained("umutbozdag/plant-identity")
|
|
|
|
| 9 |
|
| 10 |
+
# Tahmin fonksiyonu
|
| 11 |
+
def predict(image):
|
|
|
|
| 12 |
image = image.convert("RGB")
|
| 13 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
logits = outputs.logits
|
| 17 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 18 |
+
predicted_label = model.config.id2label[predicted_class_idx]
|
| 19 |
+
return predicted_label
|
| 20 |
+
|
| 21 |
+
# Arayüz
|
| 22 |
+
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
fn=predict,
|
| 24 |
+
inputs=gr.Image(type="pil", label="Bitki Fotoğrafı Yükle"),
|
| 25 |
+
outputs=gr.Textbox(label="Tahmin Edilen Bitki"),
|
| 26 |
+
title="🌿 Bitki Tanıma Sistemi",
|
| 27 |
+
description="Bir bitki fotoğrafı yükleyin",
|
| 28 |
+
article="✨ Lumi çalışıyor..."
|
| 29 |
)
|
| 30 |
+
|
| 31 |
+
iface.launch()
|