samwaugh commited on
Commit
57a6561
·
1 Parent(s): 27c513f
Files changed (1) hide show
  1. backend/runner/app.py +20 -15
backend/runner/app.py CHANGED
@@ -134,22 +134,27 @@ def presign_upload():
134
  }
135
  """
136
  run_id = uuid.uuid4().hex
137
- # We'll use a local file path as the "imageKey"
138
  image_key = f"artifacts/{run_id}.jpg"
139
- # Local upload endpoint URL (where the front-end will POST the file)
140
- upload_url = request.host_url + f"upload/{run_id}"
141
- # Return the run info and upload instructions
142
- # (fields remain empty for compatibility)
143
- response = jsonify(
144
- {
145
- "runId": run_id,
146
- "imageKey": image_key,
147
- "upload": {
148
- "url": upload_url,
149
- "fields": {}, # no fields needed for local upload
150
- },
151
- }
152
- )
 
 
 
 
 
 
153
  return response
154
 
155
 
 
134
  }
135
  """
136
  run_id = uuid.uuid4().hex
 
137
  image_key = f"artifacts/{run_id}.jpg"
138
+
139
+ # Fix: Use the correct Hugging Face Space URL
140
+ # In Hugging Face Spaces, we need to construct the URL properly
141
+ if os.getenv("HF_SPACE_URL"):
142
+ # Use environment variable if set
143
+ base_url = os.getenv("HF_SPACE_URL")
144
+ else:
145
+ # Fallback: try to get from request headers or use default
146
+ base_url = request.headers.get('X-Forwarded-Proto', 'https') + "://" + request.headers.get('X-Forwarded-Host', request.host)
147
+
148
+ upload_url = f"{base_url}/upload/{run_id}"
149
+
150
+ response = jsonify({
151
+ "runId": run_id,
152
+ "imageKey": image_key,
153
+ "upload": {
154
+ "url": upload_url,
155
+ "fields": {},
156
+ },
157
+ })
158
  return response
159
 
160