First commit
Browse files- README.md +1 -1
- app.py +206 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Text To Image
|
3 |
-
emoji:
|
4 |
colorFrom: purple
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Text To Image
|
3 |
+
emoji: 🌠
|
4 |
colorFrom: purple
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import io
|
4 |
+
import random
|
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", "Anything V4.0",
|
11 |
+
"Disney Pixar Cartoon", "Pixel Art XL", "Dalle 3 XL",
|
12 |
+
"Midjourney V4 XL", "Open Diffusion V1", "SSD 1B",
|
13 |
+
"Segmind Vega", "Animagine XL-2.0", "Animagine XL-3.0",
|
14 |
+
"OpenDalle", "OpenDalle V1.1", "PlaygroundV2 1024px aesthetic",
|
15 |
+
]
|
16 |
+
|
17 |
+
# Function to generate images from text
|
18 |
+
def generate_txt2img(current_model, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7, seed=None):
|
19 |
+
|
20 |
+
if current_model == "SD 1.5":
|
21 |
+
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
22 |
+
elif current_model == "SDXL 1.0":
|
23 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
24 |
+
elif current_model == "OpenJourney":
|
25 |
+
API_URL = "https://api-inference.huggingface.co/models/prompthero/openjourney"
|
26 |
+
elif current_model == "Anything V4.0":
|
27 |
+
API_URL = "https://api-inference.huggingface.co/models/xyn-ai/anything-v4.0"
|
28 |
+
elif current_model == "Disney Pixar Cartoon":
|
29 |
+
API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/disney-pixar-cartoon"
|
30 |
+
elif current_model == "Pixel Art XL":
|
31 |
+
API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
|
32 |
+
elif current_model == "Dalle 3 XL":
|
33 |
+
API_URL = "https://api-inference.huggingface.co/models/openskyml/dalle-3-xl"
|
34 |
+
elif current_model == "Midjourney V4 XL":
|
35 |
+
API_URL = "https://api-inference.huggingface.co/models/openskyml/midjourney-v4-xl"
|
36 |
+
elif current_model == "Open Diffusion V1":
|
37 |
+
API_URL = "https://api-inference.huggingface.co/models/openskyml/open-diffusion-v1"
|
38 |
+
elif current_model == "SSD 1B":
|
39 |
+
API_URL = "https://api-inference.huggingface.co/models/segmind/SSD-1B"
|
40 |
+
elif current_model == "Segmind Vega":
|
41 |
+
API_URL = "https://api-inference.huggingface.co/models/segmind/Segmind-Vega"
|
42 |
+
elif current_model == "Animagine XL-2.0":
|
43 |
+
API_URL = "https://api-inference.huggingface.co/models/Linaqruf/animagine-xl-2.0"
|
44 |
+
elif current_model == "Animagine XL-3.0":
|
45 |
+
API_URL = "https://api-inference.huggingface.co/models/cagliostrolab/animagine-xl-3.0"
|
46 |
+
elif current_model == "OpenDalle":
|
47 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalle"
|
48 |
+
elif current_model == "OpenDalle V1.1":
|
49 |
+
API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalleV1.1"
|
50 |
+
elif current_model == "PlaygroundV2 1024px aesthetic":
|
51 |
+
API_URL = "https://api-inference.huggingface.co/models/playgroundai/playground-v2-1024px-aesthetic"
|
52 |
+
|
53 |
+
|
54 |
+
API_TOKEN = os.environ.get("HF_READ_TOKEN")
|
55 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
56 |
+
|
57 |
+
|
58 |
+
if image_style == "None style":
|
59 |
+
payload = {
|
60 |
+
"inputs": prompt + ", 8k",
|
61 |
+
"is_negative": is_negative,
|
62 |
+
"steps": steps,
|
63 |
+
"cfg_scale": cfg_scale,
|
64 |
+
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
65 |
+
}
|
66 |
+
elif image_style == "Cinematic":
|
67 |
+
payload = {
|
68 |
+
"inputs": prompt + ", realistic, detailed, textured, skin, hair, eyes, by Alex Huguet, Mike Hill, Ian Spriggs, JaeCheol Park, Marek Denko",
|
69 |
+
"is_negative": is_negative + ", abstract, cartoon, stylized",
|
70 |
+
"steps": steps,
|
71 |
+
"cfg_scale": cfg_scale,
|
72 |
+
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
73 |
+
}
|
74 |
+
elif image_style == "Digital Art":
|
75 |
+
payload = {
|
76 |
+
"inputs": prompt + ", faded , vintage , nostalgic , by Jose Villa , Elizabeth Messina , Ryan Brenizer , Jonas Peterson , Jasmine Star",
|
77 |
+
"is_negative": is_negative + ", sharp , modern , bright",
|
78 |
+
"steps": steps,
|
79 |
+
"cfg_scale": cfg_scale,
|
80 |
+
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
81 |
+
}
|
82 |
+
elif image_style == "Portrait":
|
83 |
+
payload = {
|
84 |
+
"inputs": prompt + ", soft light, sharp, exposure blend, medium shot, bokeh, (hdr:1.4), high contrast, (cinematic, teal and orange:0.85), (muted colors, dim colors, soothing tones:1.3), low saturation, (hyperdetailed:1.2), (noir:0.4), (natural skin texture, hyperrealism, soft light, sharp:1.2)",
|
85 |
+
"is_negative": is_negative,
|
86 |
+
"steps": steps,
|
87 |
+
"cfg_scale": cfg_scale,
|
88 |
+
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
89 |
+
}
|
90 |
+
|
91 |
+
image_bytes = requests.post(API_URL, headers=headers, json=payload).content
|
92 |
+
image = Image.open(io.BytesIO(image_bytes))
|
93 |
+
return image
|
94 |
+
|
95 |
+
css = """
|
96 |
+
/* General Container Styles */
|
97 |
+
.gradio-container {
|
98 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
99 |
+
max-width: 730px !important;
|
100 |
+
margin: auto;
|
101 |
+
padding-top: 1.5rem;
|
102 |
+
text-align: center; /* Center the content horizontally */
|
103 |
+
}
|
104 |
+
/* Button Styles */
|
105 |
+
.gr-button {
|
106 |
+
color: white;
|
107 |
+
background: #007bff; /* Use a primary color for the background */
|
108 |
+
white-space: nowrap;
|
109 |
+
border: none;
|
110 |
+
padding: 10px 20px;
|
111 |
+
border-radius: 8px;
|
112 |
+
cursor: pointer;
|
113 |
+
transition: background-color 0.3s, color 0.3s;
|
114 |
+
}
|
115 |
+
.gr-button:hover {
|
116 |
+
background-color: #0056b3; /* Darken the background color on hover */
|
117 |
+
}
|
118 |
+
/* Share Button Styles */
|
119 |
+
#share-btn-container {
|
120 |
+
padding: 0.5rem !important;
|
121 |
+
background-color: #007bff; /* Use a primary color for the background */
|
122 |
+
justify-content: center;
|
123 |
+
align-items: center;
|
124 |
+
border-radius: 9999px !important;
|
125 |
+
max-width: 13rem;
|
126 |
+
margin: 0 auto; /* Center the container horizontally */
|
127 |
+
transition: background-color 0.3s;
|
128 |
+
}
|
129 |
+
#share-btn-container:hover {
|
130 |
+
background-color: #0056b3; /* Darken the background color on hover */
|
131 |
+
}
|
132 |
+
#share-btn {
|
133 |
+
all: initial;
|
134 |
+
color: #ffffff;
|
135 |
+
font-weight: 600;
|
136 |
+
cursor: pointer;
|
137 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
138 |
+
margin: 0.5rem !important;
|
139 |
+
padding: 0.5rem !important;
|
140 |
+
}
|
141 |
+
/* Other Styles */
|
142 |
+
#gallery {
|
143 |
+
min-height: 22rem;
|
144 |
+
margin: auto; /* Center the gallery horizontally */
|
145 |
+
border-bottom-right-radius: 0.5rem !important;
|
146 |
+
border-bottom-left-radius: 0.5rem !important;
|
147 |
+
}
|
148 |
+
/* Centered Container for the Image */
|
149 |
+
.image-container {
|
150 |
+
max-width: 100%; /* Set the maximum width for the container */
|
151 |
+
margin: auto; /* Center the container horizontally */
|
152 |
+
padding: 20px; /* Add padding for spacing */
|
153 |
+
border: 1px solid #ccc; /* Add a subtle border to the container */
|
154 |
+
border-radius: 10px;
|
155 |
+
overflow: hidden; /* Hide overflow if the image is larger */
|
156 |
+
max-height: 22rem; /* Set a maximum height for the container */
|
157 |
+
}
|
158 |
+
/* Set a fixed size for the image */
|
159 |
+
.image-container img {
|
160 |
+
max-width: 100%; /* Ensure the image fills the container */
|
161 |
+
height: auto; /* Maintain aspect ratio */
|
162 |
+
max-height: 100%; /* Set a maximum height for the image */
|
163 |
+
border-radius: 10px;
|
164 |
+
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
|
165 |
+
}
|
166 |
+
"""
|
167 |
+
|
168 |
+
|
169 |
+
PTI_SD_DESCRIPTION = '''
|
170 |
+
<div id="content_align">
|
171 |
+
<span style="color:darkred;font-size:32px;font-weight:bold">
|
172 |
+
MultiMulti Stable Diffusion Image Generation Simplified Version
|
173 |
+
</span>
|
174 |
+
</div>
|
175 |
+
<div id="content_align">
|
176 |
+
<span style="color:blue;font-size:16px;font-weight:bold">
|
177 |
+
Generate images directly from text prompts (no parameter tuning required)
|
178 |
+
</span>
|
179 |
+
</div>
|
180 |
+
<div id="content_align" style="margin-top: 10px;">
|
181 |
+
</div>
|
182 |
+
'''
|
183 |
+
|
184 |
+
|
185 |
+
# Creating Gradio interface
|
186 |
+
with gr.Blocks(css=css) as demo:
|
187 |
+
gr.Markdown(PTI_SD_DESCRIPTION)
|
188 |
+
with gr.Row():
|
189 |
+
with gr.Column():
|
190 |
+
current_model = gr.Dropdown(label="Select Model", choices=list_models, value=list_models[1])
|
191 |
+
text_prompt = gr.Textbox(label="Input Prompt", placeholder="Example: a cute dog", lines=2)
|
192 |
+
|
193 |
+
with gr.Column():
|
194 |
+
negative_prompt = gr.Textbox(label="Negative Prompt (optional)", placeholder="Example: blurry, unfocused", lines=2)
|
195 |
+
image_style = gr.Dropdown(label="Select Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style")
|
196 |
+
|
197 |
+
generate_button = gr.Button("Generate Image", variant='primary')
|
198 |
+
|
199 |
+
with gr.Row():
|
200 |
+
image_output = gr.Image(type="pil", label="Image Output")
|
201 |
+
|
202 |
+
generate_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
|
203 |
+
|
204 |
+
# Launch the app
|
205 |
+
demo.launch()
|
206 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
requests
|
2 |
+
pillow
|