Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, abort
|
| 2 |
+
import tsadropboxretrieval
|
| 3 |
+
import pdftotext
|
| 4 |
+
import requests
|
| 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.route('/api/process-data', methods=['POST'])
|
| 18 |
+
def process():
|
| 19 |
+
# check_api_key()
|
| 20 |
+
try:
|
| 21 |
+
|
| 22 |
+
print('In process [Try]')
|
| 23 |
+
data = request.form
|
| 24 |
+
# data = json.loads(request.data)
|
| 25 |
+
print('here',data)
|
| 26 |
+
# data = request.get_json() # Use get_json() to parse JSON data
|
| 27 |
+
# print('Received data:', data)
|
| 28 |
+
# Extracting values
|
| 29 |
+
filePath = data.get('filePath')
|
| 30 |
+
groupName = data.get('groupName')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 34 |
+
# print('3')
|
| 35 |
+
# md, res = dbxTeam.files_download(path=filePath)
|
| 36 |
+
# pdf_data = res.content
|
| 37 |
+
print('4')
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
pdftext = pdftotext.texts_from_pdf(filePath,groupName)
|
| 41 |
+
print('5')
|
| 42 |
+
|
| 43 |
+
return jsonify(pdftext)
|
| 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)
|