Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdded website to image feature
app.py
CHANGED
@@ -13,6 +13,18 @@ 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 |
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")
|
@@ -34,7 +46,15 @@ with gr.Blocks() as interface:
|
|
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,
|
@@ -52,12 +72,17 @@ with gr.Blocks() as interface:
|
|
52 |
outputs=output_image
|
53 |
)
|
54 |
|
55 |
-
generate_button = gr.Button("Refresh")
|
56 |
generate_button.click(
|
57 |
fn=html_to_image,
|
58 |
inputs=[html_code_input, width_input, height_input],
|
59 |
outputs=output_image
|
60 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
gr.Examples(
|
63 |
examples=[
|
|
|
13 |
image = Image.open(BytesIO(imgkit.from_string(html_code, False, options=options)))
|
14 |
return image
|
15 |
|
16 |
+
def website_to_image(website_link, width, height):
|
17 |
+
if not website_link:
|
18 |
+
website_link = "https://www.google.com"
|
19 |
+
options = {
|
20 |
+
'format': 'png',
|
21 |
+
'width': str(width),
|
22 |
+
'height': str(height),
|
23 |
+
'encoding': "UTF-8"
|
24 |
+
}
|
25 |
+
image = Image.open(BytesIO(imgkit.from_url(website_link, False, options=options)))
|
26 |
+
return image
|
27 |
+
|
28 |
with gr.Blocks() as interface:
|
29 |
gr.Markdown("# HTML to Image Converter")
|
30 |
gr.Markdown("Enter HTML code and set dimensions to generate an image")
|
|
|
46 |
value=720,
|
47 |
step=10,
|
48 |
)
|
49 |
+
with gr.Row(variant="panel", ):
|
50 |
+
with gr.Column():
|
51 |
+
website_link = gr.Textbox(
|
52 |
+
label="Website Link",
|
53 |
+
placeholder="https://www.google.com"
|
54 |
+
)
|
55 |
+
snapshotwebsite = gr.Button("Show Website", size="lg")
|
56 |
output_image = gr.Image(type="pil", format="PNG", show_label=False)
|
57 |
+
generate_button = gr.Button("Refresh")
|
58 |
|
59 |
html_code_input.change(
|
60 |
fn=html_to_image,
|
|
|
72 |
outputs=output_image
|
73 |
)
|
74 |
|
|
|
75 |
generate_button.click(
|
76 |
fn=html_to_image,
|
77 |
inputs=[html_code_input, width_input, height_input],
|
78 |
outputs=output_image
|
79 |
)
|
80 |
+
|
81 |
+
snapshotwebsite.click(
|
82 |
+
fn=website_to_image,
|
83 |
+
inputs=[website_link, width_input, height_input],
|
84 |
+
outputs=output_image
|
85 |
+
)
|
86 |
|
87 |
gr.Examples(
|
88 |
examples=[
|