Skip to content

Commit

Permalink
get classifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaloney111 committed Jun 9, 2024
1 parent d1bb04b commit 8268010
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
23 changes: 18 additions & 5 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

load_dotenv()
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "http://localhost:3000"}})
CORS(app) # CORS(app, resources={r"/*": {"origins": "http://localhost:3000"}})
server_thread = None
openai.api_key = os.getenv('OPEN_AI_KEY')
log = logging.getLogger('werkzeug')
Expand All @@ -37,9 +37,6 @@

df = None

def run_flask_app():
app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False)

def shutdown_server():
print("Server shutting down...")
os.kill(os.getpid(), 9)
Expand Down Expand Up @@ -80,9 +77,25 @@ def upload_file():

@app.route('/get-classifiers', methods=["GET"])
def get_classifiers():
print(build_tree('.'))
classifiers = get_available_classifiers()
return jsonify(classifiers)

def build_tree(directory, indent=''):
"""
Recursively build directory tree structure as a string.
"""
tree = indent + os.path.basename(directory) + '/' + '\n'
indent += ' '
for item in os.listdir(directory):
if item != 'node_modules' and item != 'dist' and item != 'venv' and item != '.git':
item_path = os.path.join(directory, item)
if os.path.isdir(item_path):
tree += build_tree(item_path, indent)
else:
tree += indent + item + '\n'
return tree

@app.get('/shutdown')
def shutdown():
shutdown_server()
Expand Down Expand Up @@ -243,4 +256,4 @@ def chat():
}
with open('training_progress.json', 'w') as file:
json.dump(training_progress, file)
app.run(host='0.0.0.0', port=5000, debug=True)
app.run(host='0.0.0.0', port=5000, debug=False)
3 changes: 1 addition & 2 deletions api/app.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- mode: python ; coding: utf-8 -*-

# Specify the entry point Python script
entry_point = 'app.py'

# Collect necessary data files and binaries
Expand All @@ -9,7 +8,7 @@ a = Analysis(
[entry_point],
pathex=[],
binaries=[],
datas=[],
datas=[('models', 'models')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
Expand Down
6 changes: 2 additions & 4 deletions api/available_classifiers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os

def get_available_classifiers():
model_folder = 'api/models'

model_folder = next((folder for folder in ['models', 'api/models', '_internal/models'] if os.path.exists(folder)), None)
# Verifica se o diretório 'models' existe

## retorna o path atual
if not os.path.exists(model_folder):
return []

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
"scripts": {
"start2": "set BROWSER=NONE && react-scripts start",
"start": "concurrently \"npm run start:react\" \"npm run start:flask\"",
"start-with-exe": "concurrently \"npm run start:react\" \"npm run start:flask-exe\"",
"start:react": "react-scripts start",
"start:flask": "python api/app.py",
"start:flask-exe": "cd dist/app && app.exe",
"build": "react-scripts build",
"ciBuild": "CI=true react-scripts build",
"test": "react-scripts test",
Expand Down

0 comments on commit 8268010

Please sign in to comment.