Spaces:
Sleeping
Sleeping
Commit
·
8e18ff8
1
Parent(s):
b3c57b8
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,19 +5,14 @@ import random
|
|
| 5 |
import os
|
| 6 |
from PIL import Image
|
| 7 |
|
|
|
|
| 8 |
list_models = [
|
| 9 |
-
"SDXL-1.0",
|
| 10 |
-
"
|
| 11 |
-
"OpenJourney-V4",
|
| 12 |
-
"Anything-V4",
|
| 13 |
-
"Disney-Pixar-Cartoon",
|
| 14 |
-
"Pixel-Art-XL",
|
| 15 |
-
"Dalle-3-XL",
|
| 16 |
-
"Midjourney-V4-XL",
|
| 17 |
]
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
if current_model == "SD-1.5":
|
| 23 |
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
|
@@ -77,20 +72,127 @@ def generate_txt2img(current_model, prompt, is_negative=False, image_style="None
|
|
| 77 |
image = Image.open(io.BytesIO(image_bytes))
|
| 78 |
return image
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import os
|
| 6 |
from PIL import Image
|
| 7 |
|
| 8 |
+
# List of available models
|
| 9 |
list_models = [
|
| 10 |
+
"SDXL-1.0", "SD-1.5", "OpenJourney-V4", "Anything-V4",
|
| 11 |
+
"Disney-Pixar-Cartoon", "Pixel-Art-XL", "Dalle-3-XL", "Midjourney-V4-XL",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
]
|
| 13 |
|
| 14 |
+
# Function to generate images from text
|
| 15 |
+
def generate_txt2img(current_model, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7, seed=None):
|
| 16 |
|
| 17 |
if current_model == "SD-1.5":
|
| 18 |
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
|
|
|
| 72 |
image = Image.open(io.BytesIO(image_bytes))
|
| 73 |
return image
|
| 74 |
|
| 75 |
+
|
| 76 |
+
css = """
|
| 77 |
+
/* Custom CSS here */
|
| 78 |
+
.gradio-container {
|
| 79 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 80 |
+
max-width: 900px !important;
|
| 81 |
+
margin: auto;
|
| 82 |
+
padding-top: 1.5rem;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/* Button Styles */
|
| 86 |
+
.gr-button {
|
| 87 |
+
color: white;
|
| 88 |
+
border-color: black;
|
| 89 |
+
background: black;
|
| 90 |
+
white-space: nowrap;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.gr-button:focus {
|
| 94 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
| 95 |
+
outline: none;
|
| 96 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
| 97 |
+
--tw-border-opacity: 1;
|
| 98 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
| 99 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
| 100 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
| 101 |
+
--tw-ring-opacity: .5;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/* Footer Styles */
|
| 105 |
+
.footer, .dark .footer {
|
| 106 |
+
margin-bottom: 45px;
|
| 107 |
+
margin-top: 35px;
|
| 108 |
+
text-align: center;
|
| 109 |
+
border-bottom: 1px solid #e5e5e5;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.footer > p, .dark .footer > p {
|
| 113 |
+
font-size: .8rem;
|
| 114 |
+
display: inline-block;
|
| 115 |
+
padding: 0 10px;
|
| 116 |
+
transform: translateY(10px);
|
| 117 |
+
background: white;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
.dark .footer {
|
| 121 |
+
border-color: #303030;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.dark .footer > p {
|
| 125 |
+
background: #0b0f19;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/* Share Button Styles */
|
| 129 |
+
#share-btn-container {
|
| 130 |
+
padding: 0 0.5rem !important;
|
| 131 |
+
background-color: #000000;
|
| 132 |
+
justify-content: center;
|
| 133 |
+
align-items: center;
|
| 134 |
+
border-radius: 9999px !important;
|
| 135 |
+
max-width: 13rem;
|
| 136 |
+
margin-left: auto;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
#share-btn-container:hover {
|
| 140 |
+
background-color: #060606;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
#share-btn {
|
| 144 |
+
all: initial;
|
| 145 |
+
color: #ffffff;
|
| 146 |
+
font-weight: 600;
|
| 147 |
+
cursor: pointer;
|
| 148 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 149 |
+
margin-left: 0.5rem !important;
|
| 150 |
+
padding: 0.5rem !important;
|
| 151 |
+
right: 0;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/* Animation Styles */
|
| 155 |
+
.animate-spin {
|
| 156 |
+
animation: spin 1s linear infinite;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
@keyframes spin {
|
| 160 |
+
from { transform: rotate(0deg); }
|
| 161 |
+
to { transform: rotate(360deg); }
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/* Other Styles */
|
| 165 |
+
#gallery {
|
| 166 |
+
min-height: 22rem;
|
| 167 |
+
margin-bottom: 15px;
|
| 168 |
+
margin-left: auto;
|
| 169 |
+
margin-right: auto;
|
| 170 |
+
border-bottom-right-radius: .5rem !important;
|
| 171 |
+
border-bottom-left-radius: .5rem !important;
|
| 172 |
+
}
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
# Creating Gradio interface
|
| 176 |
+
with gr.Blocks(css=css) as demo:
|
| 177 |
+
|
| 178 |
+
with gr.Row():
|
| 179 |
+
with gr.Column():
|
| 180 |
+
gr.Markdown("<h1>AI Image Generator</h1>")
|
| 181 |
+
current_model = gr.Dropdown(label="Select Model", choices=list_models, value=list_models[1])
|
| 182 |
+
text_prompt = gr.Textbox(label="Enter Prompt", placeholder="Example: a cute dog", lines=2)
|
| 183 |
+
generate_button = gr.Button("Generate Image", variant='primary')
|
| 184 |
+
|
| 185 |
+
with gr.Column():
|
| 186 |
+
gr.Markdown("<h4>Advanced Settings</h4>")
|
| 187 |
+
with gr.Accordion("Advanced Customizations", open=False):
|
| 188 |
+
negative_prompt = gr.Textbox(label="Negative Prompt (Optional)", placeholder="Example: blurry, unfocused", lines=2)
|
| 189 |
+
image_style = gr.Dropdown(label="Select Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style")
|
| 190 |
+
# Add more options if needed
|
| 191 |
+
|
| 192 |
+
with gr.Row():
|
| 193 |
+
image_output = gr.Image(type="pil", label="Output Image")
|
| 194 |
+
|
| 195 |
+
generate_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
|
| 196 |
+
|
| 197 |
+
# Launch the app
|
| 198 |
+
demo.launch()
|