Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,8 +18,8 @@ toxicity = Detoxify('original')
|
|
18 |
# Constants
|
19 |
####################################
|
20 |
AVAILABLE_MODELS = {
|
21 |
-
'TripoSR': '
|
22 |
-
'
|
23 |
}
|
24 |
|
25 |
SPACE_ID = os.getenv('SPACE_ID')
|
@@ -171,15 +171,15 @@ css = ".generating {visibility: hidden}"
|
|
171 |
|
172 |
model_names = {
|
173 |
'TripoSR': 'TripoSR',
|
174 |
-
'
|
175 |
}
|
176 |
model_licenses = {
|
177 |
'TripoSR': 'MIT License',
|
178 |
-
'
|
179 |
}
|
180 |
model_links = {
|
181 |
'TripoSR': 'https://github.com/VAST-AI-Research/TripoSR',
|
182 |
-
'
|
183 |
}
|
184 |
|
185 |
def model_license(name):
|
@@ -312,68 +312,32 @@ with gr.Blocks() as leaderboard:
|
|
312 |
leaderboard.load(get_leaderboard, inputs=[reveal_prelim], outputs=[df])
|
313 |
reloadbtn.click(get_leaderboard, inputs=[reveal_prelim], outputs=[df])
|
314 |
|
315 |
-
def synthandreturn(
|
316 |
-
|
317 |
-
if len(text) > MAX_SAMPLE_TXT_LENGTH:
|
318 |
-
raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
|
319 |
-
if len(text) < MIN_SAMPLE_TXT_LENGTH:
|
320 |
-
raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
|
321 |
-
if (
|
322 |
-
# test toxicity
|
323 |
-
toxicity.predict(text)['toxicity'] > 0.8
|
324 |
-
):
|
325 |
-
print(f'Detected toxic content! "{text}"')
|
326 |
-
raise gr.Error('Your text failed the toxicity test')
|
327 |
-
if not text:
|
328 |
-
raise gr.Error(f'You did not enter any text')
|
329 |
-
# Check language
|
330 |
-
try:
|
331 |
-
if not detect(text) == "en":
|
332 |
-
gr.Warning('Warning: The input text may not be in English')
|
333 |
-
except:
|
334 |
-
pass
|
335 |
# Get two random models
|
336 |
mdl1, mdl2 = random.sample(list(AVAILABLE_MODELS.keys()), 2)
|
337 |
-
log_text(text)
|
338 |
print("[debug] Using", mdl1, mdl2)
|
339 |
-
def predict_and_update_result(
|
340 |
try:
|
341 |
if model in AVAILABLE_MODELS:
|
342 |
-
result = router.predict(
|
343 |
else:
|
344 |
-
result = router.predict(
|
345 |
except:
|
346 |
raise gr.Error('Unable to call API, please try again :)')
|
347 |
print('Done with', model)
|
348 |
-
try:
|
349 |
-
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
|
350 |
-
audio = AudioSegment.from_file(result)
|
351 |
-
current_sr = audio.frame_rate
|
352 |
-
if current_sr > 24000:
|
353 |
-
audio = audio.set_frame_rate(24000)
|
354 |
-
try:
|
355 |
-
print('Trying to normalize audio')
|
356 |
-
audio = match_target_amplitude(audio, -20)
|
357 |
-
except:
|
358 |
-
print('[WARN] Unable to normalize audio')
|
359 |
-
audio.export(f.name, format="wav")
|
360 |
-
os.unlink(result)
|
361 |
-
result = f.name
|
362 |
-
except:
|
363 |
-
pass
|
364 |
-
|
365 |
result_storage[model] = result
|
366 |
|
367 |
results = {}
|
368 |
-
thread1 = threading.Thread(target=predict_and_update_result, args=(
|
369 |
-
thread2 = threading.Thread(target=predict_and_update_result, args=(
|
370 |
thread1.start()
|
371 |
thread2.start()
|
372 |
thread1.join()
|
373 |
thread2.join()
|
374 |
|
375 |
return (
|
376 |
-
|
377 |
"Synthesize",
|
378 |
gr.update(visible=True), # r2
|
379 |
mdl1, # model1
|
@@ -395,24 +359,24 @@ with gr.Blocks() as vote:
|
|
395 |
gr.Markdown(INSTR)
|
396 |
with gr.Group():
|
397 |
with gr.Row():
|
398 |
-
|
399 |
btn = gr.Button("Synthesize", variant='primary')
|
400 |
model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
401 |
model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
402 |
with gr.Row(visible=False) as r2:
|
403 |
with gr.Column():
|
404 |
with gr.Group():
|
405 |
-
|
406 |
abetter = gr.Button("A is better", variant='primary')
|
407 |
prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
|
408 |
with gr.Column():
|
409 |
with gr.Group():
|
410 |
-
|
411 |
bbetter = gr.Button("B is better", variant='primary')
|
412 |
prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
|
413 |
nxtroundbtn = gr.Button('Next round', visible=False)
|
414 |
-
outputs = [
|
415 |
-
btn.click(synthandreturn, inputs=[
|
416 |
nxtroundbtn.click(clear_stuff, outputs=outputs)
|
417 |
|
418 |
|
|
|
18 |
# Constants
|
19 |
####################################
|
20 |
AVAILABLE_MODELS = {
|
21 |
+
'TripoSR': 'TripoSR',
|
22 |
+
'LGM-Mini': 'LGM-Mini',
|
23 |
}
|
24 |
|
25 |
SPACE_ID = os.getenv('SPACE_ID')
|
|
|
171 |
|
172 |
model_names = {
|
173 |
'TripoSR': 'TripoSR',
|
174 |
+
'LGM-Mini': 'LGM-Mini',
|
175 |
}
|
176 |
model_licenses = {
|
177 |
'TripoSR': 'MIT License',
|
178 |
+
'LGM-Mini': 'MIT License'
|
179 |
}
|
180 |
model_links = {
|
181 |
'TripoSR': 'https://github.com/VAST-AI-Research/TripoSR',
|
182 |
+
'LGM-Mini': 'https://github.com/3DTopia/LGM',
|
183 |
}
|
184 |
|
185 |
def model_license(name):
|
|
|
312 |
leaderboard.load(get_leaderboard, inputs=[reveal_prelim], outputs=[df])
|
313 |
reloadbtn.click(get_leaderboard, inputs=[reveal_prelim], outputs=[df])
|
314 |
|
315 |
+
def synthandreturn(image):
|
316 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
# Get two random models
|
318 |
mdl1, mdl2 = random.sample(list(AVAILABLE_MODELS.keys()), 2)
|
|
|
319 |
print("[debug] Using", mdl1, mdl2)
|
320 |
+
def predict_and_update_result(image, model, result_storage):
|
321 |
try:
|
322 |
if model in AVAILABLE_MODELS:
|
323 |
+
result = router.predict(image, AVAILABLE_MODELS[model].lower(), api_name="/synthesize")
|
324 |
else:
|
325 |
+
result = router.predict(image, model.lower(), api_name="/synthesize")
|
326 |
except:
|
327 |
raise gr.Error('Unable to call API, please try again :)')
|
328 |
print('Done with', model)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
result_storage[model] = result
|
330 |
|
331 |
results = {}
|
332 |
+
thread1 = threading.Thread(target=predict_and_update_result, args=(image, mdl1, results))
|
333 |
+
thread2 = threading.Thread(target=predict_and_update_result, args=(image, mdl2, results))
|
334 |
thread1.start()
|
335 |
thread2.start()
|
336 |
thread1.join()
|
337 |
thread2.join()
|
338 |
|
339 |
return (
|
340 |
+
image,
|
341 |
"Synthesize",
|
342 |
gr.update(visible=True), # r2
|
343 |
mdl1, # model1
|
|
|
359 |
gr.Markdown(INSTR)
|
360 |
with gr.Group():
|
361 |
with gr.Row():
|
362 |
+
image = gr.Image(container=False, show_label=False, min_width=0)
|
363 |
btn = gr.Button("Synthesize", variant='primary')
|
364 |
model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
365 |
model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
366 |
with gr.Row(visible=False) as r2:
|
367 |
with gr.Column():
|
368 |
with gr.Group():
|
369 |
+
threed1 = gr.Model3D(show_label=False, show_download_button=True, show_share_button=False)
|
370 |
abetter = gr.Button("A is better", variant='primary')
|
371 |
prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
|
372 |
with gr.Column():
|
373 |
with gr.Group():
|
374 |
+
threed2 = gr.Model3D(show_label=False, show_download_button=True, show_share_button=False)
|
375 |
bbetter = gr.Button("B is better", variant='primary')
|
376 |
prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
|
377 |
nxtroundbtn = gr.Button('Next round', visible=False)
|
378 |
+
outputs = [image, btn, r2, model1, model2, threed1, threed2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
379 |
+
btn.click(synthandreturn, inputs=[image], outputs=outputs)
|
380 |
nxtroundbtn.click(clear_stuff, outputs=outputs)
|
381 |
|
382 |
|