Download app.py from Phytgoras/goruntu: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/Phytgoras/goruntu/resolve/main/app.py
- Command line
-
hf download hf://spaces/Phytgoras/goruntu/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Phytgoras/goruntu/resolve/main/app.py
1.25 kB
| import gradio as gr | |
| from keras.models import load_model | |
| import numpy as np | |
| import cv2 | |
| # Modeli yükle | |
| model = load_model("keras_model.h5", compile=False) | |
| # Etiketleri yükle | |
| class_names = open("labels.txt", "r").readlines() | |
| # Sınıflandırma fonksiyonu | |
| def classify_image(image): | |
| img_resized = cv2.resize(image, (224, 224)) # Modelin beklediği boyut | |
| img_array = np.expand_dims(img_resized, axis=0) # Batch boyutunu ekle | |
| img_array = img_array / 255.0 # Normalizasyon | |
| predictions = model.predict(img_array) | |
| class_index = np.argmax(predictions) | |
| confidence = predictions[0][class_index] | |
| return {class_names[i].strip(): float(predictions[0][i]) for i in range(len(class_names))}, f"Sınıf: {class_names[class_index].strip()} (Güven: {confidence:.2f})" | |
| # Gradio arayüzü | |
| interface = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.Image(type="numpy", label="Bir görüntü yükleyin"), | |
| outputs=[ | |
| gr.Label(num_top_classes=3, label="Tahminler"), | |
| gr.Text(label="Sonuç") | |
| ], | |
| title="Burak TURGUT Görüntü Sınıflandırma Model Programı", | |
| description="Bir görüntü yükleyin ve modelin sınıflandırmasını görün." | |
| ) | |
| # Arayüzü başlat | |
| interface.launch() |