siranida commited on
Commit
a0a557a
·
verified ·
1 Parent(s): 85cd4c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -32
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 A – artık bitkiye özel
7
- processorA = AutoImageProcessor.from_pretrained("umutbozdag/plant-identity")
8
- modelA = AutoModelForImageClassification.from_pretrained("umutbozdag/plant-identity")
9
-
10
 
11
-
12
-
13
- def predict(image, more=False):
14
  image = image.convert("RGB")
15
-
16
- # B MODELİ KODUNU GEÇİCİ OLARAK YORUMA AL
17
- # processorB = ...
18
- # modelB = ...
19
-
20
- # predict fonksiyonunun içini sadece modelA ile çalışacak şekilde sınırla:
21
- def predict(image, more=False):
22
- image = image.convert("RGB")
23
- inputsA = processorA(images=image, return_tensors="pt")
24
- logitsA = modelA(**inputsA).logits[0]
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=[gr.Image(type="pil"), gr.Checkbox(label="Daha fazlasını görmek istiyorum")],
36
- outputs=[gr.Textbox(label="Birincil Tahmin"), gr.Textbox(label="Ek Seçenekler (Geniş Model)")],
37
- title="Bitki Tanıma – Çift Model Sistemi",
38
- description="Hızlı model yüksek güvenliyse sonucunu göster, düşükse geniş model devreye girer."
 
39
  )
40
- demo.launch()
 
 
 
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()