Download app.py from starphy/yolo-app: direct link, hf CLI and curl.
- Browser
- Download file 795 Bytes
-
https://huggingface.co/spaces/starphy/yolo-app/resolve/main/app.py
- Command line
-
hf download hf://spaces/starphy/yolo-app/app.py
-
curl -L -o app.py https://huggingface.co/spaces/starphy/yolo-app/resolve/main/app.py
795 Bytes
| from flask import Flask, request, render_template | |
| from ultralytics import YOLO | |
| import os | |
| app = Flask(__name__) | |
| # Load YOLOv8 model | |
| model = YOLO("model/best.pt") | |
| def index(): | |
| result_img = None | |
| if request.method == "POST": | |
| file = request.files["image"] | |
| if file: | |
| input_path = os.path.join("static", "input.jpg") | |
| file.save(input_path) | |
| results = model(input_path) | |
| output_path = os.path.join("static", "result.jpg") | |
| results[0].save(filename=output_path) | |
| result_img = output_path | |
| return render_template("index.html", result_img=result_img) | |
| if __name__ == "__main__": | |
| port = int(os.environ.get("PORT", 7860)) | |
| app.run(host="0.0.0.0", port=port) |