🚫 Preview Not Available
Generated SVG contains errors:
{result}
"""
# Clear cache after generation
torch.cuda.empty_cache()
return svg_code, svg_display
# Authentication function using HF Space secrets
def authenticate(username, password):
"""
Authentication function for Gradio using HF Space secrets
Returns True if credentials are valid, False otherwise
"""
# Get credentials from HF Space secrets
valid_username = os.getenv("user") # This matches your secret name "user"
valid_password = os.getenv("password") # This matches your secret name "password"
# Fallback credentials if secrets are not available (for local testing)
if valid_username is None:
valid_username = "user"
print("Warning: 'user' secret not found, using fallback")
if valid_password is None:
valid_password = "password"
print("Warning: 'password' secret not found, using fallback")
return username == valid_username and password == valid_password
# Minimal CSS for slightly larger HTML preview only
custom_css = """
div[data-testid="HTML"] {
min-height: 320px !important;
}
"""
gradio_app = gr.Interface(
fn=generate_svg,
inputs=gr.Textbox(
lines=2,
placeholder="Describe the SVG you want (e.g., 'a red circle with blue border')..."
),
outputs=[
gr.Code(label="Generated SVG Code", language="html"),
gr.HTML(label="SVG Preview")
],
title="SVG Code Generator",
description="Generate SVG code from natural language using a fine-tuned LLM.",
css=custom_css
)
if __name__ == "__main__":
gradio_app.launch(auth=(os.getenv("user"), os.getenv("password")), share=True, ssr_mode=False)