Download app.py from helviz/deploy_ml: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/helviz/deploy_ml/resolve/main/app.py
- Command line
-
hf download hf://spaces/helviz/deploy_ml/app.py
-
curl -L -o app.py https://huggingface.co/spaces/helviz/deploy_ml/resolve/main/app.py
1.22 kB
| from flask import Flask, request, jsonify | |
| import torch | |
| import gdown | |
| import os | |
| from model import predict | |
| app = Flask(__name__) | |
| # Google Drive File ID (replace with your actual ID) | |
| MODEL_ID = "1RNhOLcAuVUru4kpnnyFvWeL1Fu0HIOom" | |
| MODEL_PATH = "model.pth" | |
| # Function to download model if not present | |
| def download_model(): | |
| if not os.path.exists(MODEL_PATH): | |
| print("Downloading model from Google Drive...") | |
| gdown.download(f"https://drive.google.com/uc?id={MODEL_ID}", MODEL_PATH, quiet=False) | |
| # Ensure model is downloaded before starting | |
| download_model() | |
| def home(): | |
| return "Diabetic Retinopathy Classification API is running!" | |
| def classify(): | |
| if 'file' not in request.files: | |
| return jsonify({"error": "No file uploaded"}), 400 | |
| file = request.files['file'] | |
| if file.filename == '': | |
| return jsonify({"error": "No selected file"}), 400 | |
| file_path = "temp_image.jpg" | |
| file.save(file_path) | |
| label, probabilities = predict(file_path) | |
| os.remove(file_path) | |
| return jsonify({"class": label, "probabilities": probabilities}) | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=5000) | |