dschandra commited on
Commit
68f71c4
·
verified ·
1 Parent(s): 9c6f094

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -7,9 +7,9 @@ from werkzeug.utils import secure_filename
7
 
8
  app = Flask(__name__)
9
 
10
- # Configure upload folder
11
- UPLOAD_FOLDER = 'uploads'
12
- os.makedirs(UPLOAD_FOLDER, exist_ok=True)
13
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
14
  ALLOWED_EXTENSIONS = {'mp4', 'avi', 'mov'}
15
 
@@ -111,9 +111,12 @@ def analyze():
111
  file.save(video_path)
112
 
113
  # Process video
114
- actual_path, projected_path, pitching_x, pitching_y, impact_x, impact_y, speed, spin = process_video(video_path)
115
- if actual_path is None:
116
- return jsonify({'error': projected_path}), 400 # projected_path holds error message here
 
 
 
117
 
118
  # Predict LBW decision
119
  features = np.array([[pitching_x, pitching_y, impact_x, impact_y, speed, spin]])
 
7
 
8
  app = Flask(__name__)
9
 
10
+ # Configure upload folder to use /tmp (writable on Hugging Face Spaces)
11
+ UPLOAD_FOLDER = '/tmp/uploads'
12
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True) # This should now work in /tmp
13
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
14
  ALLOWED_EXTENSIONS = {'mp4', 'avi', 'mov'}
15
 
 
111
  file.save(video_path)
112
 
113
  # Process video
114
+ result = process_video(video_path)
115
+ if result[0] is None:
116
+ os.remove(video_path) # Clean up
117
+ return jsonify({'error': result[2]}), 400 # result[2] holds error message
118
+
119
+ actual_path, projected_path, pitching_x, pitching_y, impact_x, impact_y, speed, spin = result
120
 
121
  # Predict LBW decision
122
  features = np.array([[pitching_x, pitching_y, impact_x, impact_y, speed, spin]])