Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from flask import Flask, render_template, request
|
| 3 |
import pandas as pd
|
| 4 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
@@ -88,12 +89,16 @@ def index():
|
|
| 88 |
file = request.files['file']
|
| 89 |
if file.filename != '':
|
| 90 |
try:
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
| 93 |
if recommender.load_and_process_data(filepath):
|
| 94 |
message = "File uploaded and processed successfully!"
|
| 95 |
else:
|
| 96 |
message = "Error processing the file."
|
|
|
|
|
|
|
| 97 |
except Exception as e:
|
| 98 |
message = f"File upload failed: {e}"
|
| 99 |
else:
|
|
@@ -113,5 +118,5 @@ def index():
|
|
| 113 |
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|
| 116 |
-
port = int(os.environ.get("PORT", 5000))
|
| 117 |
-
app.run(debug=True, host='0.0.0.0', port=port)
|
|
|
|
| 1 |
import os
|
| 2 |
+
import tempfile
|
| 3 |
from flask import Flask, render_template, request
|
| 4 |
import pandas as pd
|
| 5 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
|
|
| 89 |
file = request.files['file']
|
| 90 |
if file.filename != '':
|
| 91 |
try:
|
| 92 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=f".{file.filename.rsplit('.', 1)[1]}") as tmp:
|
| 93 |
+
filepath = tmp.name
|
| 94 |
+
file.save(tmp)
|
| 95 |
+
|
| 96 |
if recommender.load_and_process_data(filepath):
|
| 97 |
message = "File uploaded and processed successfully!"
|
| 98 |
else:
|
| 99 |
message = "Error processing the file."
|
| 100 |
+
|
| 101 |
+
os.remove(filepath) # Clean up temporary file
|
| 102 |
except Exception as e:
|
| 103 |
message = f"File upload failed: {e}"
|
| 104 |
else:
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
if __name__ == "__main__":
|
| 121 |
+
port = int(os.environ.get("PORT", 5000))
|
| 122 |
+
app.run(debug=True, host='0.0.0.0', port=port)
|