Spaces:
Running
Running
| from flask import Flask, request, jsonify, abort | |
| import tsadropboxretrieval | |
| import pdftotext | |
| app = Flask(__name__) | |
| # API_KEY = "adrpdftotext" # Replace with your actual API key | |
| # def check_api_key(): | |
| # api_key = request.headers.get("x-api-key") | |
| # if api_key != API_KEY: | |
| # abort(403) # Forbidden if API key is missing or incorrect | |
| def process(): | |
| # check_api_key() | |
| try: | |
| print('In process') | |
| data = request.get_json() # Correct method to get JSON data | |
| print(data) | |
| # Ensure 'pdfpath' is included in the request | |
| if 'filePath' not in data: | |
| return jsonify({"error": "Missing 'pdfpath' in request data"}), 400 | |
| pdfpath = data['filePath'] | |
| dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user') | |
| md, res = dbxTeam.files_download(path=pdfpath) | |
| pdf_data = res.content | |
| # Ensure 'pdftotext.texts_from_pdf' is a valid function | |
| pdftext = pdftotext.texts_from_pdf(pdf_data) | |
| # Prepare response | |
| response_data = { | |
| "message": "Data received", | |
| "input_data": pdftext | |
| } | |
| return jsonify(response_data) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| return jsonify({"error": str(e)}), 500 | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) | |