-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathapp.py
49 lines (40 loc) · 1.56 KB
/
app.py
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
from flask import Flask, jsonify, render_template, request
import subprocess
import os
app = Flask(__name__)
# Setting the base directory
base_dir = os.path.dirname(os.path.abspath(__file__))
app.config['UPLOAD_FOLDER'] = base_dir
SCRIPT_PATH = os.path.join(base_dir, 'legalsimplifier.gpt')
LEGAL_FILE_NAME = 'legal.pdf' # Uploaded document name
SUMMARY_FILE_NAME = 'summary.md' # The output file name
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return jsonify({'error': 'No file part'}), 400
file = request.files['file']
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400
if file:
# Process the file here to generate the summary
filename = os.path.join(app.config['UPLOAD_FOLDER'], LEGAL_FILE_NAME)
file.save(filename)
summary = process_file(file)
return jsonify({'summary': summary})
def process_file(file):
try:
# Execute the script to generate the recipe
subprocess.run(f"gptscript {SCRIPT_PATH}", shell=True, check=True)
# Read summary.md file
summary_file_path = os.path.join(app.config['UPLOAD_FOLDER'], SUMMARY_FILE_NAME)
with open(summary_file_path, 'r') as summary_file:
summary = summary_file.read()
# Return summary content
return summary
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(debug=False)