kedimestan commited on
Commit
5216e95
·
verified ·
1 Parent(s): ea12a24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -25
app.py CHANGED
@@ -1,34 +1,16 @@
1
  import gradio as gr
2
- from transformers import SwinForImageClassification, SwinImageProcessor
3
- import torch
4
  from PIL import Image
5
 
6
- # Cihaz ayarı
7
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8
-
9
- # Modeli ve işlemciyi doğrudan Hugging Face'den yükle
10
  model_name = "kedimestan/swin-base-patch4-window7-224"
11
-
12
- # Model ve işlemciyi yükle
13
- model = SwinForImageClassification.from_pretrained(model_name)
14
- processor = SwinImageProcessor.from_pretrained(model_name)
15
-
16
- model = model.to(device)
17
- model.eval()
18
 
19
  # Tahmin fonksiyonu
20
  def predict(image: Image.Image):
21
- # Görüntüyü işlemci ile işleme
22
- inputs = processor(images=image, return_tensors="pt").to(device)
23
-
24
- # Modeli kullanarak tahmin yapma
25
- with torch.no_grad():
26
- logits = model(**inputs).logits
27
-
28
- # Tahmin sonucu (maksimum sınıf)
29
- predicted_class_idx = logits.argmax(-1).item()
30
- prediction = f"Sınıf {predicted_class_idx}"
31
- return prediction
32
 
33
  # Gradio arayüzü
34
  inputs = gr.Image(type="pil", label="Görsel Yükle")
@@ -38,6 +20,6 @@ gr.Interface(
38
  fn=predict,
39
  inputs=inputs,
40
  outputs=outputs,
41
- title="Swin Transformer Görüntü Sınıflandırma",
42
  theme="default"
43
  ).launch(debug=True)
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
  from PIL import Image
4
 
5
+ # Swin modelini pipeline ile yükle
 
 
 
6
  model_name = "kedimestan/swin-base-patch4-window7-224"
7
+ classifier = pipeline("image-classification", model=model_name)
 
 
 
 
 
 
8
 
9
  # Tahmin fonksiyonu
10
  def predict(image: Image.Image):
11
+ # Görüntüyü sınıflandırma yaparak tahmin edin
12
+ result = classifier(image)
13
+ return result[0]["label"]
 
 
 
 
 
 
 
 
14
 
15
  # Gradio arayüzü
16
  inputs = gr.Image(type="pil", label="Görsel Yükle")
 
20
  fn=predict,
21
  inputs=inputs,
22
  outputs=outputs,
23
+ title="Retinoblastoma Tespiti",
24
  theme="default"
25
  ).launch(debug=True)