Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,13 @@ app = Flask(__name__)
|
|
9 |
cors = CORS(app, resources={r"/*": {"origins": "*"}})
|
10 |
app.logger.setLevel(logging.ERROR)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Define the route for the index page
|
13 |
@app.route('/', methods=['GET'])
|
14 |
def index():
|
@@ -17,15 +24,15 @@ def index():
|
|
17 |
# Define the route for processing messages
|
18 |
@app.route('/process-message', methods=['POST'])
|
19 |
def process_message_route():
|
20 |
-
user_message = request.json
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
bot_response = worker.process_prompt(user_message) # Process the user's message using the worker module
|
24 |
|
25 |
# Return the bot's response as JSON
|
26 |
-
return jsonify({
|
27 |
-
"botResponse": bot_response
|
28 |
-
}), 200
|
29 |
|
30 |
# Define the route for processing documents
|
31 |
@app.route('/process-document', methods=['POST'])
|
@@ -33,13 +40,11 @@ def process_document_route():
|
|
33 |
# Check if a file was uploaded
|
34 |
if 'file' not in request.files:
|
35 |
return jsonify({
|
36 |
-
"botResponse": "It seems like the file was not uploaded correctly
|
37 |
-
"again. If the problem persists, try using a different file"
|
38 |
}), 400
|
39 |
|
40 |
file = request.files['file'] # Extract the uploaded file from the request
|
41 |
-
|
42 |
-
file_path = file.filename # Define the path where the file will be saved
|
43 |
file.save(file_path) # Save the file
|
44 |
|
45 |
worker.process_document(file_path) # Process the document using the worker module
|
@@ -52,4 +57,4 @@ def process_document_route():
|
|
52 |
|
53 |
# Run the Flask app
|
54 |
if __name__ == "__main__":
|
55 |
-
app.run(debug=True, port=8000, host='0.0.0.0')
|
|
|
9 |
cors = CORS(app, resources={r"/*": {"origins": "*"}})
|
10 |
app.logger.setLevel(logging.ERROR)
|
11 |
|
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'])
|
21 |
def index():
|
|
|
24 |
# Define the route for processing messages
|
25 |
@app.route('/process-message', methods=['POST'])
|
26 |
def process_message_route():
|
27 |
+
user_message = request.json.get('userMessage', '') # Extract the user's message from the request
|
28 |
+
|
29 |
+
if not user_message:
|
30 |
+
return jsonify({"botResponse": "Please enter a valid message."}), 400
|
31 |
+
|
32 |
bot_response = worker.process_prompt(user_message) # Process the user's message using the worker module
|
33 |
|
34 |
# Return the bot's response as JSON
|
35 |
+
return jsonify({"botResponse": bot_response}), 200
|
|
|
|
|
36 |
|
37 |
# Define the route for processing documents
|
38 |
@app.route('/process-document', methods=['POST'])
|
|
|
40 |
# Check if a file was uploaded
|
41 |
if 'file' not in request.files:
|
42 |
return jsonify({
|
43 |
+
"botResponse": "It seems like the file was not uploaded correctly. Please try again."
|
|
|
44 |
}), 400
|
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
|
|
|
57 |
|
58 |
# Run the Flask app
|
59 |
if __name__ == "__main__":
|
60 |
+
app.run(debug=True, port=8000, host='0.0.0.0')
|