Spaces:
Sleeping

deploy_ml / app.py
helviz
initial commit
79cbb9a
Raw History Blame Contribute Delete
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()
@app.route('/')
def home():
return "Diabetic Retinopathy Classification API is running!"
@app.route('/predict', methods=['POST'])
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)