Deepakraj2006 commited on
Commit
8607b97
·
verified ·
1 Parent(s): 5aacf46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -12,9 +12,15 @@ app.logger.setLevel(logging.ERROR)
12
  # Ensure worker is initialized
13
  worker.init_llm()
14
 
15
- # Create an uploads directory if it doesn't exist
16
  UPLOAD_FOLDER = "./uploads"
17
- os.makedirs(UPLOAD_FOLDER, exist_ok=True)
 
 
 
 
 
 
18
 
19
  # Define the route for the index page
20
  @app.route('/', methods=['GET'])
@@ -45,16 +51,18 @@ def process_document_route():
45
 
46
  file = request.files['file'] # Extract the uploaded file from the request
47
  file_path = os.path.join(UPLOAD_FOLDER, file.filename) # Save file in the uploads directory
48
- file.save(file_path) # Save the file
49
 
50
- worker.process_document(file_path) # Process the document using the worker module
 
 
51
 
52
- # Return a success message as JSON
53
- return jsonify({
54
- "botResponse": "Thank you for providing your PDF document. I have analyzed it, so now you can ask me any "
55
- "questions regarding it!"
56
- }), 200
 
57
 
58
  # Run the Flask app
59
  if __name__ == "__main__":
60
- app.run(debug=True, port=8000, host='0.0.0.0')
 
12
  # Ensure worker is initialized
13
  worker.init_llm()
14
 
15
+ # Create an uploads directory if it doesn't exist (with proper permissions)
16
  UPLOAD_FOLDER = "./uploads"
17
+
18
+ try:
19
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
20
+ os.chmod(UPLOAD_FOLDER, 0o777) # Ensure full read/write permissions
21
+ print(f"Uploads directory created or exists: {UPLOAD_FOLDER}")
22
+ except Exception as e:
23
+ print(f"Error creating uploads directory: {str(e)}")
24
 
25
  # Define the route for the index page
26
  @app.route('/', methods=['GET'])
 
51
 
52
  file = request.files['file'] # Extract the uploaded file from the request
53
  file_path = os.path.join(UPLOAD_FOLDER, file.filename) # Save file in the uploads directory
 
54
 
55
+ try:
56
+ file.save(file_path) # Save the file
57
+ worker.process_document(file_path) # Process the document using the worker module
58
 
59
+ return jsonify({
60
+ "botResponse": "Thank you for providing your PDF document. I have analyzed it, so now you can ask me any "
61
+ "questions regarding it!"
62
+ }), 200
63
+ except Exception as e:
64
+ return jsonify({"botResponse": f"Error saving the file: {str(e)}"}), 500
65
 
66
  # Run the Flask app
67
  if __name__ == "__main__":
68
+ app.run(debug=True, port=8000, host='0.0.0.0')