Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,20 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
import tensorflow as tf
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
| 6 |
import json
|
| 7 |
|
| 8 |
-
# Model ve etiketleri yükle
|
| 9 |
model = tf.keras.models.load_model('animal_classifier_model.h5')
|
| 10 |
|
| 11 |
with open('class_labels.json', 'r') as f:
|
| 12 |
class_labels = json.load(f)
|
| 13 |
|
| 14 |
def preprocess_image(image):
|
| 15 |
-
# Gradio'dan gelen görüntüyü işle
|
| 16 |
image = cv2.resize(image, (128,128)) # Model için kullandığımız boyuta getir
|
| 17 |
image = image.astype('float32') / 255.0 # Normalize et
|
| 18 |
return np.expand_dims(image, axis=0) # Batch boyutu ekle
|
| 19 |
|
| 20 |
def predict_animal(image):
|
| 21 |
-
# Görüntüyü preprocessten geçir
|
| 22 |
processed_image = preprocess_image(image)
|
| 23 |
|
| 24 |
# Tahmin yap
|
|
@@ -32,7 +28,6 @@ def predict_animal(image):
|
|
| 32 |
|
| 33 |
return results
|
| 34 |
|
| 35 |
-
# Gradio arayüzünü oluştur
|
| 36 |
iface = gr.Interface(
|
| 37 |
fn=predict_animal,
|
| 38 |
inputs=gr.Image(),
|
|
@@ -42,9 +37,8 @@ iface = gr.Interface(
|
|
| 42 |
examples=[
|
| 43 |
["collie.jpg"],
|
| 44 |
["elephant.jpg"],
|
| 45 |
-
["
|
| 46 |
]
|
| 47 |
)
|
| 48 |
|
| 49 |
-
# Uygulamayı başlat
|
| 50 |
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
import json
|
| 6 |
|
|
|
|
| 7 |
model = tf.keras.models.load_model('animal_classifier_model.h5')
|
| 8 |
|
| 9 |
with open('class_labels.json', 'r') as f:
|
| 10 |
class_labels = json.load(f)
|
| 11 |
|
| 12 |
def preprocess_image(image):
|
|
|
|
| 13 |
image = cv2.resize(image, (128,128)) # Model için kullandığımız boyuta getir
|
| 14 |
image = image.astype('float32') / 255.0 # Normalize et
|
| 15 |
return np.expand_dims(image, axis=0) # Batch boyutu ekle
|
| 16 |
|
| 17 |
def predict_animal(image):
|
|
|
|
| 18 |
processed_image = preprocess_image(image)
|
| 19 |
|
| 20 |
# Tahmin yap
|
|
|
|
| 28 |
|
| 29 |
return results
|
| 30 |
|
|
|
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=predict_animal,
|
| 33 |
inputs=gr.Image(),
|
|
|
|
| 37 |
examples=[
|
| 38 |
["collie.jpg"],
|
| 39 |
["elephant.jpg"],
|
| 40 |
+
["rabbit.jpg"]
|
| 41 |
]
|
| 42 |
)
|
| 43 |
|
|
|
|
| 44 |
iface.launch()
|