|
|
from transformers import AutoImageProcessor, AutoModelForImageClassification |
|
|
from PIL import Image |
|
|
import gradio as gr |
|
|
import torch |
|
|
|
|
|
|
|
|
processor = AutoImageProcessor.from_pretrained("umutbozdag/plant-identity") |
|
|
model = AutoModelForImageClassification.from_pretrained("umutbozdag/plant-identity") |
|
|
|
|
|
|
|
|
def predict(image): |
|
|
image = image.convert("RGB") |
|
|
inputs = processor(images=image, return_tensors="pt") |
|
|
with torch.no_grad(): |
|
|
outputs = model(**inputs) |
|
|
logits = outputs.logits |
|
|
predicted_class_idx = logits.argmax(-1).item() |
|
|
predicted_label = model.config.id2label[predicted_class_idx] |
|
|
return predicted_label |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=predict, |
|
|
inputs=gr.Image(type="pil", label="Bitki Fotoğrafı Yükle"), |
|
|
outputs=gr.Textbox(label="Tahmin Edilen Bitki"), |
|
|
title="🌿 Bitki Tanıma Sistemi", |
|
|
description="Bir bitki fotoğrafı yükleyin", |
|
|
article="✨ Lumi çalışıyor..." |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|