File size: 1,085 Bytes
f467fc5
 
 
 
 
d326a56
 
 
 
 
f467fc5
d326a56
 
f467fc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 keras
import numpy as np
from PIL import Image

from huggingface_hub import hf_hub_download
import keras

# 1. Model dosyasını Hugging Face üzerinden doğrudan indirip dosya yolunu alıyoruz
model_path = hf_hub_download(repo_id="kaanakdag/corn", filename="model.keras")

# 2. Modeli indirilen spesifik dosya yolundan yüklüyoruz
model = keras.saving.load_model(model_path)
def predict(image):
    if image is None:
        return "Görsel alınamadı."
        
    # Modelinize uygun boyutlandırma (Örn: 224x224)
    img = Image.fromarray(image).resize((224, 224))
    img_array = np.array(img)
    img_array = np.expand_dims(img_array, axis=0)
    
    # Hugging Face sunucusunda tahmin işlemi
    predictions = model.predict(img_array)
    predicted_index = int(np.argmax(predictions[0]))
    confidence = float(np.max(predictions[0]))
    
    return f"Sınıf ID: {predicted_index} (Güven: %{confidence*100:.2f})"

# API uç noktasını oluşturma
iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(),
    outputs="text"
)

iface.launch()