Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,12 +12,11 @@ app.logger.setLevel(logging.ERROR)
|
|
12 |
# Ensure worker is initialized
|
13 |
worker.init_llm()
|
14 |
|
15 |
-
# ✅
|
16 |
-
UPLOAD_FOLDER = "
|
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)}")
|
@@ -25,36 +24,34 @@ except Exception as e:
|
|
25 |
# Define the route for the index page
|
26 |
@app.route('/', methods=['GET'])
|
27 |
def index():
|
28 |
-
return render_template('index.html')
|
29 |
|
30 |
# Define the route for processing messages
|
31 |
@app.route('/process-message', methods=['POST'])
|
32 |
def process_message_route():
|
33 |
-
user_message = request.json.get('userMessage', '')
|
34 |
|
35 |
if not user_message:
|
36 |
return jsonify({"botResponse": "Please enter a valid message."}), 400
|
37 |
|
38 |
-
bot_response = worker.process_prompt(user_message)
|
39 |
|
40 |
-
# Return the bot's response as JSON
|
41 |
return jsonify({"botResponse": bot_response}), 200
|
42 |
|
43 |
# Define the route for processing documents
|
44 |
@app.route('/process-document', methods=['POST'])
|
45 |
def process_document_route():
|
46 |
-
# Check if a file was uploaded
|
47 |
if 'file' not in request.files:
|
48 |
return jsonify({
|
49 |
"botResponse": "It seems like the file was not uploaded correctly. Please try again."
|
50 |
}), 400
|
51 |
|
52 |
-
file = request.files['file']
|
53 |
-
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
54 |
|
55 |
try:
|
56 |
-
file.save(file_path)
|
57 |
-
worker.process_document(file_path)
|
58 |
|
59 |
return jsonify({
|
60 |
"botResponse": "Thank you for providing your PDF document. I have analyzed it, so now you can ask me any "
|
@@ -63,6 +60,5 @@ def process_document_route():
|
|
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=
|
|
|
12 |
# Ensure worker is initialized
|
13 |
worker.init_llm()
|
14 |
|
15 |
+
# ✅ Use `/tmp/uploads/` instead of `./uploads` (since `/tmp/` is writable)
|
16 |
+
UPLOAD_FOLDER = "/tmp/uploads"
|
17 |
|
18 |
try:
|
19 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
|
20 |
print(f"Uploads directory created or exists: {UPLOAD_FOLDER}")
|
21 |
except Exception as e:
|
22 |
print(f"Error creating uploads directory: {str(e)}")
|
|
|
24 |
# Define the route for the index page
|
25 |
@app.route('/', methods=['GET'])
|
26 |
def index():
|
27 |
+
return render_template('index.html')
|
28 |
|
29 |
# Define the route for processing messages
|
30 |
@app.route('/process-message', methods=['POST'])
|
31 |
def process_message_route():
|
32 |
+
user_message = request.json.get('userMessage', '')
|
33 |
|
34 |
if not user_message:
|
35 |
return jsonify({"botResponse": "Please enter a valid message."}), 400
|
36 |
|
37 |
+
bot_response = worker.process_prompt(user_message)
|
38 |
|
|
|
39 |
return jsonify({"botResponse": bot_response}), 200
|
40 |
|
41 |
# Define the route for processing documents
|
42 |
@app.route('/process-document', methods=['POST'])
|
43 |
def process_document_route():
|
|
|
44 |
if 'file' not in request.files:
|
45 |
return jsonify({
|
46 |
"botResponse": "It seems like the file was not uploaded correctly. Please try again."
|
47 |
}), 400
|
48 |
|
49 |
+
file = request.files['file']
|
50 |
+
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
51 |
|
52 |
try:
|
53 |
+
file.save(file_path)
|
54 |
+
worker.process_document(file_path)
|
55 |
|
56 |
return jsonify({
|
57 |
"botResponse": "Thank you for providing your PDF document. I have analyzed it, so now you can ask me any "
|
|
|
60 |
except Exception as e:
|
61 |
return jsonify({"botResponse": f"Error saving the file: {str(e)}"}), 500
|
62 |
|
|
|
63 |
if __name__ == "__main__":
|
64 |
+
app.run(debug=False, port=8000, host='0.0.0.0')
|