Spaces:
Paused
Paused
| from flask import Flask, request, jsonify, abort | |
| import tsadropboxretrieval | |
| import pdftotext | |
| import requests | |
| app = Flask(__name__) | |
| def thismain(): | |
| print('ayhaga') | |
| return jsonify('done') | |
| def processtobegin(): | |
| # check_api_key() | |
| try: | |
| print('In process [Try]') | |
| # data = request.form | |
| data = request.get_json() | |
| # Extracting values | |
| filePath = data.get('filePath') | |
| groupName = data.get('groupName') | |
| print(filePath,groupName) | |
| pdftext = pdftotext.texts_from_pdf(filePath,groupName) | |
| return jsonify(pdftext) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| return jsonify({"error": str(e)}), 500 | |
| def apifunction(): | |
| try: | |
| print('In process [Try]') | |
| # data = request.form | |
| data = request.get_json() | |
| print('here',data) | |
| # Extracting values | |
| if data: | |
| # Pass the raw JSON data to the filtering function | |
| jsonOutput = pdftotext.apiFiltering(data) | |
| return jsonify(jsonOutput) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| return jsonify({"error": str(e)}), 500 | |
| def processrawan(): | |
| try: | |
| query={'loginname':'Marthe','password':'marthemain'} | |
| #token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiQURSIiwibmJmIjoiMTY4MDg1OTgzMyIsImV4cCI6IjE2ODA5MDMwMzMifQ.-FULhKD_M-cyIdSMMIYDlEo9DoZtc00yIlyXIPuyLZI" | |
| head={'Content-Type':'application/json'} | |
| response=requests.post(url="https://console.trevorsadd.co.uk/account/login",json=query,headers=head,verify=False) | |
| key=response.text | |
| head={'Content-Type':'application/json;charset=UTF-8',"Authorization":'Bearer {}'.format(key)} | |
| response=requests.post(url="https://console.trevorsadd.co.uk/project/getprojectslist",json=query,headers=head,verify=False) | |
| dict1=response.json() | |
| print('dict',dict1) | |
| print('In process [Try]') | |
| data = request.get_json() | |
| # Extracting values | |
| conversationId = data.get('conversationId') | |
| print(conversationId) | |
| # groupName = data.get('groupName') | |
| print(data) | |
| return jsonify({ | |
| 'conversationId': conversationId, | |
| 'MC_data':dict1 | |
| }) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| return jsonify({"error": str(e)}), 500 | |
| def processalltextTotext(): | |
| # 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_pdfAllText(pdfpath) | |
| # 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) | |
| # from flask import Flask, request, jsonify | |
| # app = Flask(__name__) | |
| # @app.route('/api/process-data', methods=['POST']) | |
| # def process_data(): | |
| # # Get JSON data from the request | |
| # data = request.get_json() | |
| # # Perform some processing on the data | |
| # # For example, let's just return the data back with a message | |
| # processed_data = { | |
| # 'message': 'Data received and processed successfully!', | |
| # 'received_data': data | |
| # } | |
| # return jsonify(processed_data) | |
| # if __name__ == '__main__': | |
| # app.run(host='0.0.0.0', port=7860, debug=True) |