Closed yonatanbitton closed 1 year ago
Hi, is there an update regarding this issue? Why does it crush above 100 images? Is there a better "gradio element" to use in order to show this gallery? Thanks
Hi @yonatanbitton I can't open the Space for testing (just loads forever for me). However, have you tried the gr.Gallery()
component to display the 100 images?
Hi, the space works, you should just wait a bit. That might also be a cause of the problem.
We tried gr.Gallery
, but we also have annotations for each image. Is it possible to include some annotations? Example of the annotation for a given image below (and another problem is that it is cropped).
You can include captions with the Gallery
component: just return each file along with its caption in a tuple of two strings like this: (filepath, caption)
and the caption will show up at the bottom of the image.
Is there an option for more than one captions? We have 15 captions and 10 VQA instances we'd like to show, along with some additional metadata. The current grid we have is perfect, but the problem is that it crushes without a logical error message. Could we maybe understand why does it crush? Thanks π
Oh no sorry the Gallery only supports 1 caption per image. Ok so I'm able to run your Space (after waiting a few seconds).
Just to confirm, the problem happens when you replace:
rows_number = 25
with
rows_number = int(dataset_size / columns_number)
is that right?
For the second issue, can you try setting the max_lines
parameter in Textbox
? Depending on the value set to max_lines
, you'll get different behaviors:
import gradio as gr
with gr.Blocks() as demo:
with gr.Accordion("test"):
gr.Textbox("abc\nabc\nabc\nabc"*10, max_lines=1)
gr.Textbox("abc\nabc\nabc\nabc"*10, max_lines=2)
gr.Textbox("abc\nabc\nabc\nabc", max_lines=20)
demo.launch()
produces this:
@abidlabs for the second issue, i've tried your suggestion bad sadly it doesn't work. You can see the try and the corresponding result here.
For the first problem, yes, the large number of images is probably the cause, and what you wrote does reproduce the error. We have tried this great suggestion to add pagination, ideally it would be great to present 20 images in each time, and in this way to iterate the dataset. We created this dataset viewer to try and handle the problem: link. It shows how to iterate 20 samples in each time.
However, we want to combine our original explorer (with the problem of loading too many images) with this last option of pagination. We started to try and do it, but we are not sure how to continue: Link. The question is what should be the inputs and outputs to the b1
and b2
buttons in order to show 20 samples in each time instead of the full dataset. They showed using an HTML layouts for it and we are afraid it might be too much for our use-case.
Pagination should be the answer, but the question is how to use it inside gradio. Thanks.
Hi @yonatanbitton for the max lines issue, it looks like you are using an older version of Gradio on the Space. If you go to the README and set the sdk_version
to the latest version of Gradio (3.21.0), it works. I duplicated your Space to test, and you can see it working here: https://huggingface.co/spaces/abidlabs/whoops-explorer
For adding more rows dynamically, you can't do this right now with Gradio (though we are exploring it in #2566) -- for now, if you want to have the effect of pagination, you could replace all of the images / annotations when you click on the button. But you could also just get the same effect by refreshing the page, since your images are loaded randomly from the dataset so I don't know how useful such a button would be. As a small tip, I suggest maybe reducing the number of rows that are loaded initially, this should improve the loading time significantly and allow users to get a quick idea of what the dataset includes.
Hope that helps a bit, and congrats again on the launch of a very nice dataset.
Thanks! The lines number is fixed.
For the pagination, how can I make a button that will show the next 20 images? For example like this one, and this suggested solution? A "Next 20 image" button will do the work, since I want users to be able to iterate over all of the dataset (500 images) in this explorer... Thank you
Hi @yonatanbitton I put together a simple example using a mock dataset since that was a little easier to work with than the existing script. But the same principles apply to your app:
import gradio as gr
img1 = "https://images.unsplash.com/photo-1678854321097-6919ddad32ac?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=693&q=80"
img2 = "https://images.unsplash.com/photo-1678569281064-87a3d8876cfc?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2127&q=80"
mock_dataset = []
for i in range(4):
mock_dataset.append([img1, f"Image {i}"])
for i in range(4):
mock_dataset.append([img2, f"Image {i+4}"])
for i in range(4):
mock_dataset.append([img1, f"Image {i+8}"])
for i in range(4):
mock_dataset.append([img2, f"Image {i+12}"])
with gr.Blocks() as demo:
def render_sample(sample):
image, text = sample
with gr.Column():
i = gr.Image(image)
with gr.Accordion("Details"):
t = gr.Textbox(text)
return [i, t]
def update_samples(i):
return_values = []
for j in range(4*i, 4*i+4):
return_values.extend(mock_dataset[j])
return_values.append(i+1)
return return_values
index = gr.State(1)
components_list = []
with gr.Row():
for i in range(4):
components = render_sample(mock_dataset[i])
components_list.extend(components)
btn = gr.Button("Next")
btn.click(update_samples, index, [*components_list, index])
demo.launch()
Here's how it looks:
I'll go ahead and close this issue since for general questions like this (that are not feature requests or bug reports), a better place for them is GitHub Discussions or our Discord. (I'll close this issue). But hopefully this should give you a good idea of how to proceed.
cc @yvrjsharma @freddyaboulton as it relates to dataset exploration.
@abidlabs hi,dear how to get 4 or more images from only 1 image? the 4 images are processed with different method from the one image . could you pls help me ? thx
Hi @abidlabs the above code runs perfectly but can we modify it to make user input the images instead I am trying below code for the same but gradio just hangs without display any error. Can you please help me identify why there is no error in gradio but also it doesnt through any error? import gradio as gr
def generate_mock_dataset(img1, img2): mock_dataset = []
for i in range(4):
mock_dataset.append([img1, f"Image {i}"])
for i in range(4):
mock_dataset.append([img2, f"Image {i+4}"])
return mock_dataset
def render_sample(sample): image, text = sample print(image) with gr.Column(): i = gr.Image(image) print(i) with gr.Accordion("Details"): t = gr.Textbox(text) return [i, t]
def update_samples(i): return_values = [] for j in range(4 i, 4 i + 4): return_values.extend(mock_dataset[j]) return_values.append(i + 1) return return_values
with gr.Blocks() as demo: img1 = gr.Textbox(label="Image URL 1") img2 = gr.Textbox(label="Image URL 2") btn = gr.Button("Generate Mock Dataset")
index = gr.State(1)
components_list = []
def on_button_click(img1,img2):
global mock_dataset
mock_dataset = generate_mock_dataset(img1, img2)
print(mock_dataset)
with gr.Row():
for i in range(4):
print(i)
components = render_sample(mock_dataset[i])
print(components)
components_list.extend(components)
return components_list
btn.click(on_button_click,[img1,img2],[*component_list])
demo.launch(debug=True)
Describe the bug
Hi. I have the following app in huggingface: link.
It's a 25 rows * 4 columns of images. I have 500 images, but when I try to increase the rows I receive the following error, which occurs when deploying the app, and also locally, tested with two different laptops:
The second problem is unwrapped text when deployed. When running locally, the text block shows all of the text. However, when deployed, the text is cut an "unwrapped" and it's not possible to see all of it without scrolls.
How can I fix these issues? Thanks!
Is there an existing issue for this?
Reproduction
https://huggingface.co/spaces/nlphuji/whoops_explorer
Screenshot
Logs
System Info
Severity
annoying