Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -122,28 +122,34 @@ async def upload_zip(file: UploadFile = File(...)):
|
|
122 |
|
123 |
# upload a single file from UI
|
124 |
@app.post("/upload")
|
125 |
-
async def
|
126 |
-
|
127 |
-
contents = await file.read()
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
f.write(contents)
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
|
|
147 |
|
148 |
|
149 |
|
|
|
122 |
|
123 |
# upload a single file from UI
|
124 |
@app.post("/upload")
|
125 |
+
async def upload_images(files: List[UploadFile] = File(...)):
|
126 |
+
responses = []
|
|
|
127 |
|
128 |
+
for file in files:
|
129 |
+
filename = file.filename
|
130 |
+
contents = await file.read()
|
|
|
131 |
|
132 |
+
temp_path = f"/tmp/{filename}"
|
133 |
+
with open(temp_path, "wb") as f:
|
134 |
+
f.write(contents)
|
135 |
+
|
136 |
+
try:
|
137 |
+
upload_file(
|
138 |
+
path_or_fileobj=temp_path,
|
139 |
+
path_in_repo=f"demo/{filename}",
|
140 |
+
repo_id="rahul7star/ohamlab",
|
141 |
+
repo_type="model",
|
142 |
+
commit_message=f"Upload {filename} to demo folder",
|
143 |
+
token=True,
|
144 |
+
)
|
145 |
+
responses.append({"filename": filename, "status": "β
uploaded"})
|
146 |
+
except Exception as e:
|
147 |
+
responses.append({"filename": filename, "status": f"β failed: {str(e)}"})
|
148 |
+
|
149 |
+
# Optional: clean up local temp file
|
150 |
+
os.remove(temp_path)
|
151 |
|
152 |
+
return {"results": responses}
|
153 |
|
154 |
|
155 |
|