Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -163,7 +163,7 @@ def upload_and_train_detection(
|
|
163 |
try:
|
164 |
proj = ws.project(project_slug)
|
165 |
except Exception as e:
|
166 |
-
if "does not exist" in str(e):
|
167 |
proj = ws.create_project(
|
168 |
project_slug,
|
169 |
annotation=project_type,
|
@@ -192,13 +192,41 @@ def upload_and_train_detection(
|
|
192 |
project_type=project_type
|
193 |
)
|
194 |
|
195 |
-
# 4) Generate new version & train
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
proj.version(str(version_num)).train()
|
201 |
|
|
|
202 |
m = proj.version(str(version_num)).model
|
203 |
return f"{m['base_url']}{m['id']}?api_key={api_key}"
|
204 |
|
|
|
163 |
try:
|
164 |
proj = ws.project(project_slug)
|
165 |
except Exception as e:
|
166 |
+
if "does not exist" in str(e).lower():
|
167 |
proj = ws.create_project(
|
168 |
project_slug,
|
169 |
annotation=project_type,
|
|
|
192 |
project_type=project_type
|
193 |
)
|
194 |
|
195 |
+
# 4) Generate new version & train, with fallback on unsupported-request errors
|
196 |
+
try:
|
197 |
+
version_num = proj.generate_version(settings={
|
198 |
+
"augmentation": {},
|
199 |
+
"preprocessing": {},
|
200 |
+
})
|
201 |
+
except RuntimeError as e:
|
202 |
+
msg = str(e).lower()
|
203 |
+
if "unsupported request" in msg or "does not exist" in msg:
|
204 |
+
suffix = "-v3" if project_slug.endswith("-v2") else "-v2"
|
205 |
+
new_slug = project_slug + suffix
|
206 |
+
proj = ws.create_project(
|
207 |
+
new_slug,
|
208 |
+
annotation=project_type,
|
209 |
+
project_type=project_type,
|
210 |
+
project_license=project_license
|
211 |
+
)
|
212 |
+
project_slug = new_slug
|
213 |
+
ws.upload_dataset(
|
214 |
+
dataset_path,
|
215 |
+
project_slug,
|
216 |
+
project_license=project_license,
|
217 |
+
project_type=project_type
|
218 |
+
)
|
219 |
+
version_num = proj.generate_version(settings={
|
220 |
+
"augmentation": {},
|
221 |
+
"preprocessing": {},
|
222 |
+
})
|
223 |
+
else:
|
224 |
+
raise
|
225 |
+
|
226 |
+
# 5) Kick off training
|
227 |
proj.version(str(version_num)).train()
|
228 |
|
229 |
+
# 6) Return the hosted endpoint
|
230 |
m = proj.version(str(version_num)).model
|
231 |
return f"{m['base_url']}{m['id']}?api_key={api_key}"
|
232 |
|