-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (63 loc) · 2.27 KB
/
main.py
File metadata and controls
73 lines (63 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
===========================================================
Program: Main
Programmer/s: Cristina C. Villasor
Date Written: June 15, 2025
Last Revised: Nov. 18, 2025
Purpose: Entry point for the Flask application
Program Fits in the General System Design:
- Entry point of the system
- Registers routes for handling URL
===========================================================
"""
from flask import Flask
from routes import bp as routes_bp
from dotenv import load_dotenv
import modal
import os
load_dotenv() # Load .env file
app = modal.App("coin") # Initialize Modal app
uploads_volume = modal.Volume.from_name("uploads-storage", create_if_missing=True)
annot_volume = modal.Volume.from_name("annot-storage", create_if_missing=True)
# Create dependencies
image = (
modal.Image.debian_slim(python_version="3.11")
.apt_install("libgl1", "libglib2.0-0", "ffmpeg")
.pip_install(
"flask",
"flask-wtf",
"wtforms",
"torch",
"torchvision",
"werkzeug",
"huggingface-hub",
"transformers",
"Pillow",
"opencv-contrib-python-headless",
"tensorflow",
"numpy",
"scipy",
"python-dotenv",
"modal",
)
.add_local_dir(
local_path=".",
remote_path="/root",
ignore=[".git", "__pycache__", "venv", "node_modules/",
"static/uploads", "static/annotated", ".gitignore"]
)
)
flask_app = Flask(__name__) # Create Flask app
flask_app.config["SECRET_KEY"] = os.getenv("CONFIG") # Set config key for CSRF and Modal
flask_app.config["UPLOADS_VOLUME"] = uploads_volume
flask_app.config["ANNOT_VOLUME"] = annot_volume
flask_app.register_blueprint(routes_bp) # Register routes blueprint
# Define modal function
@app.function(image=image, gpu="T4", timeout=1800, volumes={"/root/static/uploads": uploads_volume,
"/root/static/annotated": annot_volume})
@modal.wsgi_app() # Create WSGI webpoint
def modal_app(): # Serve Flask app on Modal
"""Serve Flask app on Modal"""
return flask_app
if __name__ == "__main__": # Run Flask app locally
flask_app.run(debug=True)