Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,11 +27,12 @@ def upload():
|
|
| 27 |
if not os.path.exists(filename):
|
| 28 |
return jsonify({"error": "Download failed"}), 500
|
| 29 |
|
| 30 |
-
#
|
| 31 |
print(f"⏳ Uploading to Hugging Face Bucket...")
|
| 32 |
with open(filename, "rb") as f:
|
| 33 |
content = f.read()
|
| 34 |
|
|
|
|
| 35 |
upload_url = f"https://huggingface.co/api/buckets/{BUCKET_NAME}/upload/{filename}"
|
| 36 |
headers = {
|
| 37 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
@@ -44,12 +45,10 @@ def upload():
|
|
| 44 |
if resp.status_code in [200, 201]:
|
| 45 |
link = f"https://huggingface.co/buckets/{BUCKET_NAME}/blob/main/{filename}"
|
| 46 |
print(f"✅ Uploaded Successfully!")
|
| 47 |
-
return jsonify({
|
| 48 |
-
"success": True,
|
| 49 |
-
"link": link
|
| 50 |
-
})
|
| 51 |
else:
|
| 52 |
print(f"❌ Upload Failed: {resp.status_code}")
|
|
|
|
| 53 |
return jsonify({"error": f"Upload failed: {resp.status_code}"}), 500
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
|
|
|
| 27 |
if not os.path.exists(filename):
|
| 28 |
return jsonify({"error": "Download failed"}), 500
|
| 29 |
|
| 30 |
+
# ✅ SAHI HF BUCKET UPLOAD (API v2)
|
| 31 |
print(f"⏳ Uploading to Hugging Face Bucket...")
|
| 32 |
with open(filename, "rb") as f:
|
| 33 |
content = f.read()
|
| 34 |
|
| 35 |
+
# Correct endpoint for buckets (without /storage/)
|
| 36 |
upload_url = f"https://huggingface.co/api/buckets/{BUCKET_NAME}/upload/{filename}"
|
| 37 |
headers = {
|
| 38 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
|
|
| 45 |
if resp.status_code in [200, 201]:
|
| 46 |
link = f"https://huggingface.co/buckets/{BUCKET_NAME}/blob/main/{filename}"
|
| 47 |
print(f"✅ Uploaded Successfully!")
|
| 48 |
+
return jsonify({"success": True, "link": link})
|
|
|
|
|
|
|
|
|
|
| 49 |
else:
|
| 50 |
print(f"❌ Upload Failed: {resp.status_code}")
|
| 51 |
+
print(f"Response: {resp.text}")
|
| 52 |
return jsonify({"error": f"Upload failed: {resp.status_code}"}), 500
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|