SVGhtml / app.py
Felguk's picture
Create app.py
c75d598 verified
raw
history blame
1 kB
import gradio as gr
def svg_to_html(svg_file):
# Read the SVG file content
with open(svg_file.name, 'r') as file:
svg_code = file.read()
# Create a basic HTML template with the SVG code embedded
html_content = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG to HTML</title>
</head>
<body>
{svg_code}
</body>
</html>
"""
return html_content, svg_code
# Define the Gradio interface
iface = gr.Interface(
fn=svg_to_html,
inputs=gr.inputs.File(label="Upload SVG File"),
outputs=[
gr.outputs.Textbox(lines=15, label="Generated HTML"),
gr.outputs.HTML(label="SVG Preview")
],
title="SVG to HTML Converter",
description="Upload an SVG file to see the generated HTML code and a preview of the SVG",
theme=Nymbo/Nymbo_theme_5
)
# Launch the interface
iface.launch()