Spaces:
Runtime error
Runtime error
File size: 1,572 Bytes
975d1b2 4ad299d 975d1b2 4ad299d 975d1b2 4ad299d 975d1b2 4ad299d 975d1b2 4ad299d 975d1b2 4ad299d 975d1b2 |
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 |
import os
from flask import Blueprint, render_template, request, send_file, jsonify
from .utils.vector_db import process_files_to_vectors
from .utils.zip_handler import handle_zip_upload # We'll create this utility
import zipfile
v_bp = Blueprint('routes', __name__)
@v_bp.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
v_uploaded_file = request.files.get('file')
if not v_uploaded_file or not v_uploaded_file.filename.endswith('.zip'):
return jsonify({'error': 'Please upload a valid zip file.'}), 400
# Save uploaded ZIP
v_upload_path = os.path.join('app/uploads', v_uploaded_file.filename)
v_uploaded_file.save(v_upload_path)
# Extract the ZIP
v_extracted_folder = handle_zip_upload(v_upload_path)
# Process to create or update vector DB
v_result_folder = process_files_to_vectors(v_extracted_folder)
# Zip the resulting vectors folder for download
v_result_zip_path = os.path.join('app/uploads', 'vector_db_result.zip')
obj_zip = zipfile.ZipFile(v_result_zip_path, 'w', zipfile.ZIP_DEFLATED)
for v_root, _, v_files in os.walk(v_result_folder):
for v_file in v_files:
v_full_path = os.path.join(v_root, v_file)
v_arcname = os.path.relpath(v_full_path, start=v_result_folder)
obj_zip.write(v_full_path, arcname=v_arcname)
obj_zip.close()
return send_file(v_result_zip_path, as_attachment=True)
return render_template('index.html')
|