| import gradio as gr |
| import keras |
| import numpy as np |
| from PIL import Image |
|
|
| from huggingface_hub import hf_hub_download |
| import keras |
|
|
| |
| model_path = hf_hub_download(repo_id="kaanakdag/corn", filename="model.keras") |
|
|
| |
| model = keras.saving.load_model(model_path) |
| def predict(image): |
| if image is None: |
| return "Görsel alınamadı." |
| |
| |
| img = Image.fromarray(image).resize((224, 224)) |
| img_array = np.array(img) |
| img_array = np.expand_dims(img_array, axis=0) |
| |
| |
| 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})" |
|
|
| |
| iface = gr.Interface( |
| fn=predict, |
| inputs=gr.Image(), |
| outputs="text" |
| ) |
|
|
| iface.launch() |