-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
88 lines (67 loc) · 2.48 KB
/
app.py
File metadata and controls
88 lines (67 loc) · 2.48 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# STANDARD python imports
import os
import json
import logging
import shutil
import logging
# Imports for building RESTful API
from flask import Flask
from flask_caching import Cache
# Import from BRAD
import sys
sys.path.append('../BRAD') # TODO: change this to work from PIP
# from BRAD.endpoints import bp as brad_endpoints_bp # Import the Blueprint
# from BRAD.endpoints import set_globals, initiate_start
from BRAD.agent import Agent
from BRAD.constants import TOOL_MODULES
# Video endpoints
from video_endpoints import bp as video_endpoints_bp
from video_endpoints import set_globals as set_globals_network
from video_endpoints import initiate_start as initiate_start_network
# Modify BRAD configs on the fly
CONFIG_FILE = "config.json"
script_dir = os.path.abspath(os.path.dirname(__file__))
with open(CONFIG_FILE, "r") as file:
config = json.load(file)
if config.get("log_path") == "output-logs":
config["log_path"] = os.path.join(script_dir, "output-logs")
with open(CONFIG_FILE, "w") as file:
json.dump(config, file, indent=4)
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Configue caching
cache = Cache(config={'CACHE_TYPE': 'SimpleCache'})
# def create_app():
# Directory structure
UPLOAD_FOLDER = '/usr/src/uploads'
DATABASE_FOLDER = '/usr/src/RAG_Database/'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
# Redundant
TOOL_MODULES = TOOL_MODULES
# Set up app
app = Flask(__name__)
print(f"{app.root_path=}")
# set cache for the app
cache.init_app(app)
CACHE = cache
# Data directories setup
DATA_FOLDER = os.path.join(app.root_path, 'data')
UPLOAD_FOLDER = os.path.join(DATA_FOLDER, 'uploads')
DATABASE_FOLDER = os.path.join(DATA_FOLDER, 'RAG_Database')
print(f"{DATA_FOLDER=}")
print(f"{UPLOAD_FOLDER=}")
print(f"{DATABASE_FOLDER=}")
if not os.path.exists(DATA_FOLDER):
os.makedirs(DATA_FOLDER)
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
if not os.path.exists(DATABASE_FOLDER):
os.makedirs(DATABASE_FOLDER)
# set_globals(DATA_FOLDER, UPLOAD_FOLDER, DATABASE_FOLDER, ALLOWED_EXTENSIONS, TOOL_MODULES, CACHE)
set_globals_network(DATA_FOLDER, UPLOAD_FOLDER, DATABASE_FOLDER, ALLOWED_EXTENSIONS, TOOL_MODULES, CACHE)
# initiate_start()
initiate_start_network()
# Register the Blueprint for the endpoints
# app.register_blueprint(brad_endpoints_bp)
app.register_blueprint(video_endpoints_bp)