diff --git a/requirements.txt b/requirements.txt index f8f71dd..9706f08 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ genanki==0.8.0 Pillow -openai \ No newline at end of file +openai +flask \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000..7bfc869 --- /dev/null +++ b/server.py @@ -0,0 +1,42 @@ +from flask import Flask, request, send_from_directory, jsonify +import os +import tempfile # For creating temporary directories +import shutil # For removing directories + +from pipeline import pipeline + +app = Flask(__name__) + +@app.route('/generate-deck', methods=['POST']) +def generate_deck(): + # Assuming images are sent as multipart/form-data + if 'image' not in request.files: + return jsonify({'error': 'No image part'}), 400 + + images = request.files.getlist('image') + + if not images or all([img.filename == '' for img in images]): + return jsonify({'error': 'No selected file'}), 400 + + # Create a temporary directory to store multiple images + temp_dir = tempfile.mkdtemp() + + image_paths = [] + for img in images: + image_path = os.path.join(temp_dir, img.filename) + img.save(image_path) + image_paths.append(image_path) + + try: + # Run the pipeline using the saved images + # You might need to modify your pipeline to accept and handle multiple images + pipeline(temp_dir) # Assuming pipeline works per directory of images + return send_from_directory('.', 'output.apkg', as_attachment=True) + except Exception as e: + return jsonify({'error': str(e)}), 500 + finally: + # Cleanup: Remove the temporary directory and its content + shutil.rmtree(temp_dir) + +if __name__ == '__main__': + app.run(debug=True)