Sidd-SQY commited on
Commit
521e8e6
·
verified ·
1 Parent(s): 6154876

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -13,7 +13,6 @@ def html_to_image(html_code, width, height):
13
  image = Image.open(BytesIO(imgkit.from_string(html_code, False, options=options)))
14
  return image
15
 
16
- # Create the Gradio interface
17
  with gr.Blocks() as interface:
18
  gr.Markdown("# HTML to Image Converter")
19
  gr.Markdown("Enter HTML code and set dimensions to generate an image")
@@ -23,30 +22,36 @@ with gr.Blocks() as interface:
23
  label="HTML Code",
24
  language="html",
25
  lines=30,
26
- interactive=True # Make the code input interactive
27
  )
28
  width_input = gr.Number(
29
  label="Width",
30
  value=1280,
31
- step=10,
32
- info="Width in pixels"
33
  )
34
  height_input = gr.Number(
35
  label="Height",
36
  value=720,
37
  step=10,
38
- info="Height in pixels"
39
  )
40
  output_image = gr.Image(type="pil", format="PNG", show_label=False)
41
 
42
- # Trigger the function when the HTML Code input changes
43
  html_code_input.change(
44
  fn=html_to_image,
45
  inputs=[html_code_input, width_input, height_input],
46
  outputs=output_image
47
  )
 
 
 
 
 
 
 
 
 
 
48
 
49
- # Alternatively, trigger function on button click (optional)
50
  generate_button = gr.Button("Refresh")
51
  generate_button.click(
52
  fn=html_to_image,
@@ -54,7 +59,6 @@ with gr.Blocks() as interface:
54
  outputs=output_image
55
  )
56
 
57
- # Add examples
58
  gr.Examples(
59
  examples=[
60
  ["<div style='background: linear-gradient(45deg, #ff6b6b, #4ecdc4); padding: 20px; border-radius: 10px;'><h1 style='color: white; font-family: Arial;'>Hello, World!</h1></div>", 800, 400],
@@ -63,6 +67,5 @@ with gr.Blocks() as interface:
63
  inputs=[html_code_input, width_input, height_input]
64
  )
65
 
66
- # Launch the Gradio app
67
  if __name__ == "__main__":
68
  interface.launch()
 
13
  image = Image.open(BytesIO(imgkit.from_string(html_code, False, options=options)))
14
  return image
15
 
 
16
  with gr.Blocks() as interface:
17
  gr.Markdown("# HTML to Image Converter")
18
  gr.Markdown("Enter HTML code and set dimensions to generate an image")
 
22
  label="HTML Code",
23
  language="html",
24
  lines=30,
25
+ interactive=True
26
  )
27
  width_input = gr.Number(
28
  label="Width",
29
  value=1280,
30
+ step=10
 
31
  )
32
  height_input = gr.Number(
33
  label="Height",
34
  value=720,
35
  step=10,
 
36
  )
37
  output_image = gr.Image(type="pil", format="PNG", show_label=False)
38
 
 
39
  html_code_input.change(
40
  fn=html_to_image,
41
  inputs=[html_code_input, width_input, height_input],
42
  outputs=output_image
43
  )
44
+ width_input.change(
45
+ fn=html_to_image,
46
+ inputs=[html_code_input, width_input, height_input],
47
+ outputs=output_image
48
+ )
49
+ height_input.change(
50
+ fn=html_to_image,
51
+ inputs=[html_code_input, width_input, height_input],
52
+ outputs=output_image
53
+ )
54
 
 
55
  generate_button = gr.Button("Refresh")
56
  generate_button.click(
57
  fn=html_to_image,
 
59
  outputs=output_image
60
  )
61
 
 
62
  gr.Examples(
63
  examples=[
64
  ["<div style='background: linear-gradient(45deg, #ff6b6b, #4ecdc4); padding: 20px; border-radius: 10px;'><h1 style='color: white; font-family: Arial;'>Hello, World!</h1></div>", 800, 400],
 
67
  inputs=[html_code_input, width_input, height_input]
68
  )
69
 
 
70
  if __name__ == "__main__":
71
  interface.launch()