Download app.py from kaanakdag/corn-api: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/kaanakdag/corn-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/kaanakdag/corn-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/kaanakdag/corn-api/resolve/main/app.py
1.09 kB
| 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() |