File size: 926 Bytes
33067ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()