icons / app.py
gdo's picture
Create app.py
33067ea verified
raw
history blame contribute delete
926 Bytes
import gradio as gr
import requests
def generate_icon(description):
"""
Generates an icon based on text input using the Iconify API.
"""
# Format text to match Iconify's naming conventions
icon_name = description.replace(' ', '-').lower()
iconify_url = f"https://api.iconify.design/mdi:{icon_name}.svg"
# Check if icon exists
response = requests.get(iconify_url)
if response.status_code == 200:
# Return an HTML tag to embed the SVG
return f'<img src="{iconify_url}" width="100" height="100">'
else:
return "❌ Icon not found. Try a different description."
# Gradio Interface
demo = gr.Interface(
fn=generate_icon,
inputs=gr.Textbox(label="Enter Icon Description"),
outputs=gr.HTML(label="Generated Icon"),
title="AI-Powered Icon Generator",
description="Generate icons based on text descriptions using the Iconify API."
)
demo.launch()