Spaces:
Runtime error
Runtime error
| 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__) | |
| 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') | |