File size: 1,227 Bytes
37ce3b0
e88f3f9
 
37ce3b0
e88f3f9
 
37ce3b0
d85bd71
37ce3b0
 
 
e88f3f9
a3ca2ff
37ce3b0
 
 
e88f3f9
37ce3b0
 
 
 
 
 
 
 
 
 
 
a3ca2ff
37ce3b0
 
 
 
e88f3f9
37ce3b0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing import image

# Modeli yükle
model = tf.keras.models.load_model("model.h5")

# Tahmin fonksiyonu
def predict_image(img):
    # Görüntüyü 224x224 boyutuna küçült
    img = img.resize((224, 224))
    
    # Görüntüyü modelin beklediği formatta (numpy array) hazırla
    img_array = np.array(img) / 255.0  # Piksel değerlerini normalize et
    img_array = np.expand_dims(img_array, axis=0)  # Modelin beklediği 4D input formatına getir

    # Tahmin yap
    prediction = model.predict(img_array)
    
    # En yüksek tahmin sonucunu al
    predicted_class = np.argmax(prediction, axis=1)[0]
    
    # Geri dönüşüm malzemesi etiketlerini burada belirle
    class_names = ['Plastik', 'Kağıt', 'Cam', 'Metal']
    
    # Sonuçları döndür
    return class_names[predicted_class]

# Gradio arayüzünü oluştur
iface = gr.Interface(fn=predict_image,
                     inputs=gr.inputs.Image(shape=(224, 224)),  # Görüntüyü 224x224 boyutlarına getir
                     outputs="text")  # Çıktıyı metin olarak göster (yani tahmin edilen etiket)

# Uygulamayı başlat
iface.launch(share=True)