multimodalart HF Staff commited on
Commit
773d81c
·
verified ·
1 Parent(s): 497ac8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -10
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
 
3
  # Problematic URL that triggers the SSRF validation error
4
  # This is a legitimate Hugging Face URL that should be allowed
5
- problematic_url = "https://huggingface.co/Norod78/JojosoStyle-flux-lora/resolve/main/samples/1725217578243__000000000_0.jpg"
6
 
7
  # Sample data with image URLs (similar to loras_state)
8
  sample_data = [
@@ -13,18 +13,32 @@ sample_data = [
13
  }
14
  ]
15
 
16
- def dummy_function(text_input, state_data):
17
  """
18
  This function should be called when button is clicked,
19
- but the error occurs before it even executes.
20
  """
21
  print("Function was called!") # This should appear in logs but doesn't
22
- return f"Processed: {text_input}", state_data
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  # Create the interface
25
  with gr.Blocks() as demo:
26
  gr.Markdown("# Gradio SSRF Bug Reproduction")
27
  gr.Markdown("Click the button below. You should see an error about hostname validation.")
 
28
 
29
  # State containing URLs that trigger the issue
30
  state_var = gr.State(sample_data)
@@ -32,18 +46,25 @@ with gr.Blocks() as demo:
32
  # Simple text input
33
  text_input = gr.Textbox(label="Enter some text", value="test")
34
 
35
- # Output
 
 
 
 
 
 
 
36
  output = gr.Textbox(label="Output")
37
 
38
  # Button that triggers the error
39
- button = gr.Button("Click me - this will fail")
40
 
41
- # This should work fine, but fails with:
42
- # ValueError: Hostname cas-bridge-direct.xethub.hf.co failed validation
43
  button.click(
44
- fn=dummy_function,
45
  inputs=[text_input, state_var],
46
- outputs=[output, state_var]
47
  )
48
 
49
  if __name__ == "__main__":
 
2
 
3
  # Problematic URL that triggers the SSRF validation error
4
  # This is a legitimate Hugging Face URL that should be allowed
5
+ problematic_url = "https://cas-bridge-direct.xethub.hf.co/some-file.jpg"
6
 
7
  # Sample data with image URLs (similar to loras_state)
8
  sample_data = [
 
13
  }
14
  ]
15
 
16
+ def add_item_function(text_input, state_data):
17
  """
18
  This function should be called when button is clicked,
19
+ but the error occurs before it even executes when gallery is in outputs.
20
  """
21
  print("Function was called!") # This should appear in logs but doesn't
22
+
23
+ # Add a new item to state
24
+ new_item = {
25
+ "title": f"New Item: {text_input}",
26
+ "image": problematic_url, # This URL in the return value triggers SSRF
27
+ "repo": "new/repo"
28
+ }
29
+ state_data.append(new_item)
30
+
31
+ # Format data for gallery: list of (image, title) tuples
32
+ gallery_data = [(item["image"], item["title"]) for item in state_data]
33
+
34
+ # Use gr.update() to match the original code pattern exactly
35
+ return f"Added: {text_input}", state_data, gr.update(value=gallery_data)
36
 
37
  # Create the interface
38
  with gr.Blocks() as demo:
39
  gr.Markdown("# Gradio SSRF Bug Reproduction")
40
  gr.Markdown("Click the button below. You should see an error about hostname validation.")
41
+ gr.Markdown("The error occurs when the function tries to return data that will update a gallery with HuggingFace URLs.")
42
 
43
  # State containing URLs that trigger the issue
44
  state_var = gr.State(sample_data)
 
46
  # Simple text input
47
  text_input = gr.Textbox(label="Enter some text", value="test")
48
 
49
+ # Gallery that will be updated with the problematic URLs
50
+ gallery = gr.Gallery(
51
+ label="Gallery",
52
+ value=[(item["image"], item["title"]) for item in sample_data],
53
+ columns=3
54
+ )
55
+
56
+ # Output textbox
57
  output = gr.Textbox(label="Output")
58
 
59
  # Button that triggers the error
60
+ button = gr.Button("Add item - this will fail")
61
 
62
+ # This fails with: ValueError: Hostname cas-bridge-direct.xethub.hf.co failed validation
63
+ # The error occurs when Gradio tries to process the gallery update with the HF URLs
64
  button.click(
65
+ fn=add_item_function,
66
  inputs=[text_input, state_var],
67
+ outputs=[output, state_var, gallery] # Including gallery in outputs triggers the error
68
  )
69
 
70
  if __name__ == "__main__":