Marthee commited on
Commit
1e2d425
·
verified ·
1 Parent(s): 1e346d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -54
app.py CHANGED
@@ -1,70 +1,70 @@
1
  from flask import Flask, request, jsonify, abort
2
- # import tsadropboxretrieval
3
- # import pdftotext
4
 
5
- # app = Flask(__name__)
6
- # # API_KEY = "adrpdftotext" # Replace with your actual API key
7
 
8
- # # def check_api_key():
9
- # # api_key = request.headers.get("x-api-key")
10
- # # if api_key != API_KEY:
11
- # # abort(403) # Forbidden if API key is missing or incorrect
12
- # @app.route("/",methods=["GET", "POST"])
13
- # def thismain():
14
- # print('ayhaga')
15
- # return jsonify('done')
16
 
17
- # @app.post('/process')
18
- # def process():
19
- # # check_api_key()
20
- # try:
21
- # print('In process')
22
- # data = request.get_json() # Correct method to get JSON data
23
- # print(data)
24
 
25
- # # Ensure 'pdfpath' is included in the request
26
- # if 'filePath' not in data:
27
- # return jsonify({"error": "Missing 'pdfpath' in request data"}), 400
28
 
29
- # pdfpath = data['filePath']
30
 
31
- # dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
32
- # md, res = dbxTeam.files_download(path=pdfpath)
33
- # pdf_data = res.content
34
 
35
- # # Ensure 'pdftotext.texts_from_pdf' is a valid function
36
- # pdftext = pdftotext.texts_from_pdf(pdf_data)
37
 
38
- # # Prepare response
39
- # response_data = {
40
- # "message": "Data received",
41
- # "input_data": pdftext
42
- # }
43
- # return jsonify(response_data)
44
 
45
- # except Exception as e:
46
- # print(f"Error: {e}")
47
- # return jsonify({"error": str(e)}), 500
48
 
49
- # if __name__ == '__main__':
50
- # app.run(host='0.0.0.0', port=7860)
51
- from flask import Flask, request, jsonify
52
 
53
- app = Flask(__name__)
54
 
55
- @app.route('/api/process-data', methods=['POST'])
56
- def process_data():
57
- # Get JSON data from the request
58
- data = request.get_json()
59
 
60
- # Perform some processing on the data
61
- # For example, let's just return the data back with a message
62
- processed_data = {
63
- 'message': 'Data received and processed successfully!',
64
- 'received_data': data
65
- }
66
 
67
- return jsonify(processed_data)
68
 
69
- if __name__ == '__main__':
70
- app.run(host='0.0.0.0', port=7860, debug=True)
 
1
  from flask import Flask, request, jsonify, abort
2
+ import tsadropboxretrieval
3
+ import pdftotext
4
 
5
+ app = Flask(__name__)
6
+ # API_KEY = "adrpdftotext" # Replace with your actual API key
7
 
8
+ # def check_api_key():
9
+ # api_key = request.headers.get("x-api-key")
10
+ # if api_key != API_KEY:
11
+ # abort(403) # Forbidden if API key is missing or incorrect
12
+ @app.route("/",methods=["GET", "POST"])
13
+ def thismain():
14
+ print('ayhaga')
15
+ return jsonify('done')
16
 
17
+ @app.post('/process')
18
+ def process():
19
+ # check_api_key()
20
+ try:
21
+ print('In process')
22
+ data = request.get_json() # Correct method to get JSON data
23
+ print(data)
24
 
25
+ # Ensure 'pdfpath' is included in the request
26
+ if 'filePath' not in data:
27
+ return jsonify({"error": "Missing 'pdfpath' in request data"}), 400
28
 
29
+ pdfpath = data['filePath']
30
 
31
+ dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
32
+ md, res = dbxTeam.files_download(path=pdfpath)
33
+ pdf_data = res.content
34
 
35
+ # Ensure 'pdftotext.texts_from_pdf' is a valid function
36
+ pdftext = pdftotext.texts_from_pdf(pdf_data)
37
 
38
+ # Prepare response
39
+ response_data = {
40
+ "message": "Data received",
41
+ "input_data": pdftext
42
+ }
43
+ return jsonify(response_data)
44
 
45
+ except Exception as e:
46
+ print(f"Error: {e}")
47
+ return jsonify({"error": str(e)}), 500
48
 
49
+ if __name__ == '__main__':
50
+ app.run(host='0.0.0.0', port=7860)
51
+ # from flask import Flask, request, jsonify
52
 
53
+ # app = Flask(__name__)
54
 
55
+ # @app.route('/api/process-data', methods=['POST'])
56
+ # def process_data():
57
+ # # Get JSON data from the request
58
+ # data = request.get_json()
59
 
60
+ # # Perform some processing on the data
61
+ # # For example, let's just return the data back with a message
62
+ # processed_data = {
63
+ # 'message': 'Data received and processed successfully!',
64
+ # 'received_data': data
65
+ # }
66
 
67
+ # return jsonify(processed_data)
68
 
69
+ # if __name__ == '__main__':
70
+ # app.run(host='0.0.0.0', port=7860, debug=True)