Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -285,109 +285,156 @@ import gradio as gr
|
|
285 |
# gr.Interface(fn=main_fun, inputs=[image_pil, x_units, y_units, text_prompt], outputs=[output]).launch(share=True, debug=True)
|
286 |
|
287 |
|
288 |
-
block = gr.Blocks().queue()
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
-
|
372 |
-
|
373 |
-
#
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
#
|
379 |
-
#
|
380 |
-
#
|
381 |
-
#
|
382 |
-
#
|
383 |
-
#
|
384 |
-
#
|
385 |
-
#
|
386 |
-
#
|
387 |
-
#
|
388 |
-
#
|
389 |
-
|
390 |
-
|
391 |
-
# print(f'torch.cuda.is_available = {torch.cuda.is_available()}')
|
392 |
-
# computer_info()
|
393 |
-
block.launch(server_name='0.0.0.0')
|
|
|
285 |
# gr.Interface(fn=main_fun, inputs=[image_pil, x_units, y_units, text_prompt], outputs=[output]).launch(share=True, debug=True)
|
286 |
|
287 |
|
288 |
+
# block = gr.Blocks().queue()
|
289 |
+
# with block:
|
290 |
+
# with gr.Row():
|
291 |
+
# with gr.Column():
|
292 |
+
# # task_types = ["detection"]
|
293 |
+
# # if sam_enable:
|
294 |
+
# # task_types.append("segment")
|
295 |
+
# # if inpainting_enable:
|
296 |
+
# # task_types.append("inpainting")
|
297 |
+
# # task_types.append("outpainting")
|
298 |
+
# # if lama_cleaner_enable:
|
299 |
+
# # task_types.append("remove")
|
300 |
+
# # if ram_enable:
|
301 |
+
# # task_types.append("relate anything")
|
302 |
+
# # if kosmos_enable:
|
303 |
+
# # task_types.append("Kosmos-2")
|
304 |
|
305 |
+
# input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload",
|
306 |
+
# height=512, brush_color='#00FFFF', mask_opacity=0.6)
|
307 |
+
# # task_type = gr.Radio(task_types, value="detection",
|
308 |
+
# # label='Task type', visible=True)
|
309 |
+
# # mask_source_radio = gr.Radio([mask_source_draw, mask_source_segment],
|
310 |
+
# # value=mask_source_segment, label="Mask from",
|
311 |
+
# # visible=False)
|
312 |
+
# x_units = gr.Slider(minimum=50, maximum=300, step=1, value=10, label="x_units")
|
313 |
+
# y_units = gr.Slider(minimum=30, maximum=300, step=0.1, value=5, label="y_units")
|
314 |
+
# text_prompt = gr.Textbox(lines=1, label="Prompt")
|
315 |
+
# # image_pil = gr.components.Image(type="filepath", label="Input Image")
|
316 |
+
# # output = gr.components.Image(type="numpy", label="Output Image")
|
317 |
|
318 |
+
# run_button = gr.Button(label="Run", visible=True)
|
319 |
+
# # with gr.Accordion("Advanced options", open=False) as advanced_options:
|
320 |
+
# # box_threshold = gr.Slider(
|
321 |
+
# # label="Box Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.001
|
322 |
+
# # )
|
323 |
+
# # text_threshold = gr.Slider(
|
324 |
+
# # label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001
|
325 |
+
# # )
|
326 |
+
# # iou_threshold = gr.Slider(
|
327 |
+
# # label="IOU Threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.001
|
328 |
+
# # )
|
329 |
+
# # inpaint_mode = gr.Radio(["merge", "first"], value="merge", label="inpaint_mode")
|
330 |
+
# # with gr.Row():
|
331 |
+
# # with gr.Column(scale=1):
|
332 |
+
# # remove_mode = gr.Radio(["segment", "rectangle"], value="segment", label='remove mode')
|
333 |
+
# # with gr.Column(scale=1):
|
334 |
+
# # remove_mask_extend = gr.Textbox(label="remove_mask_extend", value='10')
|
335 |
+
|
336 |
+
# with gr.Column():
|
337 |
+
# image_gallery = gr.Gallery(label="result images", show_label=True, elem_id="gallery", height=512, visible=True
|
338 |
+
# ).style(preview=True, columns=[5], object_fit="scale-down", height="auto")
|
339 |
+
# # time_cost = gr.Textbox(label="Time cost by step (ms):", visible=False, interactive=False)
|
340 |
+
|
341 |
+
# # kosmos_output = gr.Image(type="pil", label="result images", visible=False)
|
342 |
+
# # kosmos_text_output = gr.HighlightedText(
|
343 |
+
# # label="Generated Description",
|
344 |
+
# # combine_adjacent=False,
|
345 |
+
# # show_legend=True,
|
346 |
+
# # visible=False,
|
347 |
+
# # ).style(color_map=color_map)
|
348 |
+
# # # record which text span (label) is selected
|
349 |
+
# # selected = gr.Number(-1, show_label=False, placeholder="Selected", visible=False)
|
350 |
+
|
351 |
+
# # # record the current `entities`
|
352 |
+
# # entity_output = gr.Textbox(visible=False)
|
353 |
+
|
354 |
+
# # # get the current selected span label
|
355 |
+
# # def get_text_span_label(evt: gr.SelectData):
|
356 |
+
# # if evt.value[-1] is None:
|
357 |
+
# # return -1
|
358 |
+
# # return int(evt.value[-1])
|
359 |
+
# # # and set this information to `selected`
|
360 |
+
# # kosmos_text_output.select(get_text_span_label, None, selected)
|
361 |
|
362 |
+
# # update output image when we change the span (enity) selection
|
363 |
+
# # def update_output_image(img_input, image_output, entities, idx):
|
364 |
+
# # entities = ast.literal_eval(entities)
|
365 |
+
# # updated_image = draw_entity_boxes_on_image(img_input, entities, entity_index=idx)
|
366 |
+
# # return updated_image
|
367 |
+
# # selected.change(update_output_image, [kosmos_output, kosmos_output, entity_output, selected], [kosmos_output])
|
368 |
+
|
369 |
+
# run_button.click(fn=main_fun, inputs=[image_pil, x_units, y_units, text_prompt], outputs=[image_gallery], show_progress=True, queue=True)
|
370 |
+
|
371 |
+
# # mask_source_radio.change(fn=change_radio_display, inputs=[task_type, mask_source_radio],
|
372 |
+
# # outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation])
|
373 |
+
# # task_type.change(fn=change_radio_display, inputs=[task_type, mask_source_radio],
|
374 |
+
# # outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation,
|
375 |
+
# # image_gallery, kosmos_input, kosmos_output, kosmos_text_output
|
376 |
+
# # ])
|
377 |
+
|
378 |
+
# # DESCRIPTION = f'### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
379 |
+
# # if lama_cleaner_enable:
|
380 |
+
# # DESCRIPTION += f'Remove(cleaner) from [lama-cleaner](https://github.com/Sanster/lama-cleaner). <br>'
|
381 |
+
# # if kosmos_enable:
|
382 |
+
# # DESCRIPTION += f'Kosmos-2 from [Kosmos-2](https://github.com/microsoft/unilm/tree/master/kosmos-2). <br>'
|
383 |
+
# # if ram_enable:
|
384 |
+
# # DESCRIPTION += f'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
|
385 |
+
# # DESCRIPTION += f'Thanks for their excellent work.'
|
386 |
+
# # DESCRIPTION += f'<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. \
|
387 |
+
# # <a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
388 |
+
# # gr.Markdown(DESCRIPTION)
|
389 |
+
|
390 |
+
# # print(f'device = {device}')
|
391 |
+
# # print(f'torch.cuda.is_available = {torch.cuda.is_available()}')
|
392 |
+
# # computer_info()
|
393 |
+
# block.launch(server_name='0.0.0.0')
|
394 |
+
|
395 |
+
|
396 |
+
image_blocks = gr.Blocks()
|
397 |
+
with image_blocks as demo:
|
398 |
+
# gr.HTML(read_content("header.html"))
|
399 |
+
with gr.Group():
|
400 |
+
with gr.Box():
|
401 |
+
with gr.Row():
|
402 |
+
with gr.Column():
|
403 |
+
image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload").style(height=400)
|
404 |
+
with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
|
405 |
+
text_prompt = gr.Textbox(placeholder = 'Your prompt (what you want in place of what is erased)', show_label=False, elem_id="input-text")
|
406 |
+
x_units = gr.Slider(minimum=50, maximum=300, step=1, value=10, label="x_units")
|
407 |
+
y_units = gr.Slider(minimum=30, maximum=300, step=0.1, value=5, label="y_units")
|
408 |
+
# text_prompt = gr.Textbox(lines=1, label="Prompt")
|
409 |
+
btn = gr.Button("Shift!").style(
|
410 |
+
margin=False,
|
411 |
+
rounded=(False, True, True, False),
|
412 |
+
full_width=False,
|
413 |
+
)
|
414 |
+
with gr.Column():
|
415 |
+
image_out = gr.Image(label="Output", elem_id="output-img").style(height=400)
|
416 |
+
# with gr.Group(elem_id="share-btn-container"):
|
417 |
+
# community_icon = gr.HTML(community_icon_html, visible=False)
|
418 |
+
# loading_icon = gr.HTML(loading_icon_html, visible=False)
|
419 |
+
# share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
|
420 |
|
421 |
+
|
422 |
+
btn.click(fn=main_fun, inputs=[image, x_units, y_units, text_prompt], outputs=[image_out])
|
423 |
+
# share_button.click(None, [], [], _js=share_js)
|
424 |
+
|
425 |
+
# gr.HTML(
|
426 |
+
# """
|
427 |
+
# <div class="footer">
|
428 |
+
# <p>Model by <a href="https://huggingface.co/runwayml" style="text-decoration: underline;" target="_blank">RunwayML</a> - Gradio Demo by 🤗 Hugging Face
|
429 |
+
# </p>
|
430 |
+
# </div>
|
431 |
+
# <div class="acknowledgments">
|
432 |
+
# <p><h4>LICENSE</h4>
|
433 |
+
# The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
|
434 |
+
# <p><h4>Biases and content acknowledgment</h4>
|
435 |
+
# Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
|
436 |
+
# </div>
|
437 |
+
# """
|
438 |
+
# )
|
439 |
+
|
440 |
+
image_blocks.launch()
|
|
|
|
|
|