Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- Dockerfile +2 -2
- app.py +25 -4
Dockerfile
CHANGED
@@ -16,8 +16,8 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
16 |
# Copy application files
|
17 |
COPY . .
|
18 |
|
19 |
-
# Create necessary directories
|
20 |
-
RUN mkdir -p uploads results
|
21 |
|
22 |
# Expose port
|
23 |
EXPOSE 7860
|
|
|
16 |
# Copy application files
|
17 |
COPY . .
|
18 |
|
19 |
+
# Create necessary directories with proper permissions
|
20 |
+
RUN mkdir -p uploads results && chmod 755 uploads results
|
21 |
|
22 |
# Expose port
|
23 |
EXPOSE 7860
|
app.py
CHANGED
@@ -23,8 +23,13 @@ app.config['UPLOAD_FOLDER'] = 'uploads'
|
|
23 |
app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # 500MB max file size
|
24 |
socketio = SocketIO(app, cors_allowed_origins="*")
|
25 |
|
26 |
-
# Ensure upload directory exists
|
27 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Global variables for progress tracking
|
30 |
current_progress = {'step': 'idle', 'progress': 0, 'details': ''}
|
@@ -730,12 +735,28 @@ def upload_file():
|
|
730 |
normalization_path = os.path.join(app.config['UPLOAD_FOLDER'], norm_filename)
|
731 |
norm_file.save(normalization_path)
|
732 |
|
733 |
-
# Check if required files exist
|
734 |
if not os.path.exists(model_path):
|
735 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
736 |
|
737 |
if not os.path.exists(normalization_path):
|
738 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
739 |
|
740 |
# Save CSV file
|
741 |
csv_filename = secure_filename(csv_file.filename)
|
|
|
23 |
app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # 500MB max file size
|
24 |
socketio = SocketIO(app, cors_allowed_origins="*")
|
25 |
|
26 |
+
# Ensure upload directory exists with proper permissions
|
27 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
28 |
+
# Fix permissions for Hugging Face Spaces
|
29 |
+
try:
|
30 |
+
os.chmod(app.config['UPLOAD_FOLDER'], 0o755)
|
31 |
+
except:
|
32 |
+
pass # In case we don't have permission to change permissions
|
33 |
|
34 |
# Global variables for progress tracking
|
35 |
current_progress = {'step': 'idle', 'progress': 0, 'details': ''}
|
|
|
735 |
normalization_path = os.path.join(app.config['UPLOAD_FOLDER'], norm_filename)
|
736 |
norm_file.save(normalization_path)
|
737 |
|
738 |
+
# Check if required files exist - try both uploaded and default locations
|
739 |
if not os.path.exists(model_path):
|
740 |
+
# If uploaded model not found, try default location
|
741 |
+
if model_path.startswith(app.config['UPLOAD_FOLDER']):
|
742 |
+
default_model_path = 'best_model.pth'
|
743 |
+
if os.path.exists(default_model_path):
|
744 |
+
model_path = default_model_path
|
745 |
+
else:
|
746 |
+
return jsonify({'success': False, 'error': f'Model file not found in uploads ({model_path}) or root (best_model.pth). Please upload a model file.'})
|
747 |
+
else:
|
748 |
+
return jsonify({'success': False, 'error': f'Model file not found: {model_path}'})
|
749 |
|
750 |
if not os.path.exists(normalization_path):
|
751 |
+
# If uploaded normalization not found, try default location
|
752 |
+
if normalization_path.startswith(app.config['UPLOAD_FOLDER']):
|
753 |
+
default_norm_path = 'normalization_params_1_atlanttic_regular_intervals_with_lat_lon_velocity_and_time_difference_filter_outlier_segment_min_20_points.json'
|
754 |
+
if os.path.exists(default_norm_path):
|
755 |
+
normalization_path = default_norm_path
|
756 |
+
else:
|
757 |
+
return jsonify({'success': False, 'error': f'Normalization file not found in uploads ({normalization_path}) or root. Please upload a normalization file.'})
|
758 |
+
else:
|
759 |
+
return jsonify({'success': False, 'error': f'Normalization file not found: {normalization_path}'})
|
760 |
|
761 |
# Save CSV file
|
762 |
csv_filename = secure_filename(csv_file.filename)
|