Spaces:
Running
Running
new files
Browse files- app.py +127 -0
- circle.png +0 -0
- requirements.txt +57 -0
- square.png +0 -0
app.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Define paths to reference images for shapes
|
5 |
+
shape_images = {
|
6 |
+
"Circle": "circle.png",
|
7 |
+
"Square": "square.png"
|
8 |
+
# "Triangle": "triangle.png"
|
9 |
+
}
|
10 |
+
|
11 |
+
# Define color palette as hex codes or color names
|
12 |
+
color_palette = {
|
13 |
+
"Red": "#FF0000",
|
14 |
+
"Blue": "#0000FF",
|
15 |
+
"Green": "#008000",
|
16 |
+
"Yellow": "#FFFF00",
|
17 |
+
"Purple": "#800080",
|
18 |
+
"Orange": "#FFA500"
|
19 |
+
}
|
20 |
+
default_color = "Red"
|
21 |
+
default_color_hex = color_palette[default_color]
|
22 |
+
|
23 |
+
def generate_icon(shape, color, description):
|
24 |
+
client = Client("multimodalart/stable-cascade")
|
25 |
+
color_hex = color_palette.get(color, color_palette[default_color])
|
26 |
+
print(color_hex)
|
27 |
+
print(shape)
|
28 |
+
print(description)
|
29 |
+
# Construct prompt based on user description and selected characteristics
|
30 |
+
prompt = (f"Create a {description} icon in the shape of a {shape} with {color} color..")
|
31 |
+
|
32 |
+
# Call the API with the constructed prompt
|
33 |
+
result = client.predict(
|
34 |
+
prompt=prompt,
|
35 |
+
negative_prompt="",
|
36 |
+
seed=0,
|
37 |
+
width=1024,
|
38 |
+
height=1024,
|
39 |
+
prior_num_inference_steps=20,
|
40 |
+
prior_guidance_scale=4,
|
41 |
+
decoder_num_inference_steps=10,
|
42 |
+
decoder_guidance_scale=0,
|
43 |
+
num_images_per_prompt=1,
|
44 |
+
api_name="/run"
|
45 |
+
)
|
46 |
+
|
47 |
+
# Return the result image
|
48 |
+
return result
|
49 |
+
|
50 |
+
def gradio_interface():
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
gr.Markdown("### AI Icon Generator")
|
53 |
+
custom_css = """
|
54 |
+
<style>
|
55 |
+
.custom-button {
|
56 |
+
width: 150px; /* Set the width of the button */
|
57 |
+
height: 40px; /* Set the height of the button */
|
58 |
+
font-size: 16px; /* Set the font size */
|
59 |
+
text-align: center; /* Center text */
|
60 |
+
}
|
61 |
+
.output-image {
|
62 |
+
width: 200px; /* Set the width of the output image */
|
63 |
+
height: 200px; /* Set the height of the output image */
|
64 |
+
object-fit: contain; /* Ensure the image scales proportionally */
|
65 |
+
}
|
66 |
+
</style>
|
67 |
+
"""
|
68 |
+
gr.HTML(custom_css)
|
69 |
+
# Display reference images for shapes as selectable options
|
70 |
+
shape_options = gr.Radio(
|
71 |
+
choices=list(shape_images.keys()),
|
72 |
+
label="Select Shape"
|
73 |
+
)
|
74 |
+
|
75 |
+
# Display shape images with fixed sizes using a layout
|
76 |
+
with gr.Row():
|
77 |
+
for shape, path in shape_images.items():
|
78 |
+
with gr.Column():
|
79 |
+
gr.Image(
|
80 |
+
value=path,
|
81 |
+
label=shape,
|
82 |
+
type="pil",
|
83 |
+
elem_classes="shape-image",
|
84 |
+
height=100,
|
85 |
+
width=100
|
86 |
+
) # Remove this line
|
87 |
+
|
88 |
+
# Dropdown for color palette
|
89 |
+
color_options = gr.Dropdown(
|
90 |
+
choices=list(color_palette.keys()),
|
91 |
+
label="Select Color",
|
92 |
+
value=default_color
|
93 |
+
)
|
94 |
+
# color_hex = gr.Textbox(
|
95 |
+
# label="Color Hex Code",
|
96 |
+
# value=color_palette[default_color],
|
97 |
+
# visible=False
|
98 |
+
# )
|
99 |
+
|
100 |
+
# # Update color hex code when a color is selected
|
101 |
+
# def update_color_hex(color):
|
102 |
+
# return color_palette[color]
|
103 |
+
|
104 |
+
# color_options.change(fn=update_color_hex, inputs=[color_options], outputs=[color_hex])
|
105 |
+
|
106 |
+
# Textbox for additional description
|
107 |
+
description_text = gr.Textbox(
|
108 |
+
label="Describe the Icon",
|
109 |
+
placeholder="e.g., textile, steel, modern, futuristic"
|
110 |
+
)
|
111 |
+
|
112 |
+
with gr.Row():
|
113 |
+
submit_btn = gr.Button("Generate Icon", elem_classes="custom-button")
|
114 |
+
output_image = gr.Image(type="pil", elem_classes="output-image")
|
115 |
+
|
116 |
+
# Connect the function to the button
|
117 |
+
submit_btn.click(
|
118 |
+
generate_icon,
|
119 |
+
inputs=[shape_options, color_options, description_text],
|
120 |
+
outputs=[output_image]
|
121 |
+
)
|
122 |
+
|
123 |
+
demo.launch(share=True)
|
124 |
+
|
125 |
+
# Run the Gradio interface
|
126 |
+
if __name__ == "__main__":
|
127 |
+
gradio_interface()
|
circle.png
ADDED
requirements.txt
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
annotated-types==0.7.0
|
3 |
+
anyio==4.4.0
|
4 |
+
certifi==2024.8.30
|
5 |
+
charset-normalizer==3.3.2
|
6 |
+
click==8.1.7
|
7 |
+
contourpy==1.3.0
|
8 |
+
cycler==0.12.1
|
9 |
+
fastapi==0.112.4
|
10 |
+
ffmpy==0.4.0
|
11 |
+
filelock==3.15.4
|
12 |
+
fonttools==4.53.1
|
13 |
+
fsspec==2024.9.0
|
14 |
+
gradio==4.43.0
|
15 |
+
gradio_client==1.3.0
|
16 |
+
h11==0.14.0
|
17 |
+
httpcore==1.0.5
|
18 |
+
httpx==0.27.2
|
19 |
+
huggingface-hub==0.24.6
|
20 |
+
idna==3.8
|
21 |
+
importlib_resources==6.4.4
|
22 |
+
Jinja2==3.1.4
|
23 |
+
kiwisolver==1.4.7
|
24 |
+
markdown-it-py==3.0.0
|
25 |
+
MarkupSafe==2.1.5
|
26 |
+
matplotlib==3.9.2
|
27 |
+
mdurl==0.1.2
|
28 |
+
numpy==2.1.1
|
29 |
+
orjson==3.10.7
|
30 |
+
packaging==24.1
|
31 |
+
pandas==2.2.2
|
32 |
+
pillow==10.4.0
|
33 |
+
pydantic==2.9.0
|
34 |
+
pydantic_core==2.23.2
|
35 |
+
pydub==0.25.1
|
36 |
+
Pygments==2.18.0
|
37 |
+
pyparsing==3.1.4
|
38 |
+
python-dateutil==2.9.0.post0
|
39 |
+
python-multipart==0.0.9
|
40 |
+
pytz==2024.1
|
41 |
+
PyYAML==6.0.2
|
42 |
+
requests==2.32.3
|
43 |
+
rich==13.8.0
|
44 |
+
ruff==0.6.4
|
45 |
+
semantic-version==2.10.0
|
46 |
+
shellingham==1.5.4
|
47 |
+
six==1.16.0
|
48 |
+
sniffio==1.3.1
|
49 |
+
starlette==0.38.4
|
50 |
+
tomlkit==0.12.0
|
51 |
+
tqdm==4.66.5
|
52 |
+
typer==0.12.5
|
53 |
+
typing_extensions==4.12.2
|
54 |
+
tzdata==2024.1
|
55 |
+
urllib3==2.2.2
|
56 |
+
uvicorn==0.30.6
|
57 |
+
websockets==12.0
|
square.png
ADDED