|
import gradio as gr |
|
|
|
|
|
|
|
problematic_url = "https://huggingface.co/Norod78/Flux_1_Dev_LoRA_Paper-Cutout-Style/resolve/main/08a19840b6214b76b0607b2f9d5a7e28_63159b9d98124c008efb1d36446a615c.png" |
|
|
|
|
|
sample_data = [ |
|
{ |
|
"title": "Sample LoRA", |
|
"image": problematic_url, |
|
"repo": "some/repo" |
|
} |
|
] |
|
|
|
def add_item_function(text_input, state_data): |
|
""" |
|
This function should be called when button is clicked, |
|
but the error occurs before it even executes when gallery is in outputs. |
|
""" |
|
print("Function was called!") |
|
|
|
|
|
new_item = { |
|
"title": f"New Item: {text_input}", |
|
"image": problematic_url, |
|
"repo": "new/repo" |
|
} |
|
state_data.append(new_item) |
|
|
|
|
|
gallery_data = [(item["image"], item["title"]) for item in state_data] |
|
|
|
|
|
return f"Added: {text_input}", state_data, gr.update(value=gallery_data) |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Gradio SSRF Bug Reproduction") |
|
gr.Markdown("Click the button below. You should see an error about hostname validation.") |
|
gr.Markdown("The error occurs when the function tries to return data that will update a gallery with HuggingFace URLs.") |
|
|
|
|
|
state_var = gr.State(sample_data) |
|
|
|
|
|
text_input = gr.Textbox(label="Enter some text", value="test") |
|
|
|
|
|
gallery = gr.Gallery( |
|
label="Gallery", |
|
value=[(item["image"], item["title"]) for item in sample_data], |
|
columns=3 |
|
) |
|
|
|
|
|
output = gr.Textbox(label="Output") |
|
|
|
|
|
button = gr.Button("Add item - this will fail") |
|
|
|
|
|
|
|
button.click( |
|
fn=add_item_function, |
|
inputs=[text_input, state_var], |
|
outputs=[output, state_var, gallery] |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |