Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,6 @@ import io
|
|
| 12 |
from io import BytesIO
|
| 13 |
import base64
|
| 14 |
import re
|
| 15 |
-
from typing import Tuple
|
| 16 |
from gradio_client import Client
|
| 17 |
from fake_useragent import UserAgent
|
| 18 |
import random
|
|
@@ -22,8 +21,8 @@ from fastapi import FastAPI
|
|
| 22 |
app = FastAPI()
|
| 23 |
@app.get("/")
|
| 24 |
|
| 25 |
-
def query(prompt, negative_prompt, task,
|
| 26 |
-
result = {prompt:"prompt", negative_prompt:"negative_prompt", task:"task", steps:"steps", sampler:"sampler", cfg_scale:"cfg_scale",
|
| 27 |
print(result)
|
| 28 |
try:
|
| 29 |
language = detect(prompt)
|
|
@@ -182,55 +181,7 @@ def mirror(image_output, scale_by, method, gfpgan, codeformer):
|
|
| 182 |
img = Image.open(BytesIO(response2.content))
|
| 183 |
return img
|
| 184 |
|
| 185 |
-
#####
|
| 186 |
|
| 187 |
-
style_list = [
|
| 188 |
-
|
| 189 |
-
{
|
| 190 |
-
"name": "2560 x 1440",
|
| 191 |
-
"prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
| 192 |
-
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
| 193 |
-
},
|
| 194 |
-
|
| 195 |
-
{
|
| 196 |
-
"name": "Photo",
|
| 197 |
-
"prompt": "cinematic photo {prompt}. 35mm photograph, film, bokeh, professional, 4k, highly detailed",
|
| 198 |
-
"negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
|
| 199 |
-
},
|
| 200 |
-
|
| 201 |
-
{
|
| 202 |
-
"name": "Cinematic",
|
| 203 |
-
"prompt": "cinematic still {prompt}. emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
|
| 204 |
-
"negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
|
| 205 |
-
},
|
| 206 |
-
|
| 207 |
-
{
|
| 208 |
-
"name": "Anime",
|
| 209 |
-
"prompt": "anime artwork {prompt}. anime style, key visual, vibrant, studio anime, highly detailed",
|
| 210 |
-
"negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
|
| 211 |
-
},
|
| 212 |
-
{
|
| 213 |
-
"name": "3D Model",
|
| 214 |
-
"prompt": "professional 3d model {prompt}. octane render, highly detailed, volumetric, dramatic lighting",
|
| 215 |
-
"negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
|
| 216 |
-
},
|
| 217 |
-
{
|
| 218 |
-
"name": "(No style)",
|
| 219 |
-
"prompt": "{prompt}",
|
| 220 |
-
"negative_prompt": "",
|
| 221 |
-
},
|
| 222 |
-
]
|
| 223 |
-
|
| 224 |
-
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
| 225 |
-
STYLE_NAMES = list(styles.keys())
|
| 226 |
-
DEFAULT_STYLE_NAME = "2560 x 1440"
|
| 227 |
-
|
| 228 |
-
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 229 |
-
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 230 |
-
if not negative:
|
| 231 |
-
negative = ""
|
| 232 |
-
return p.replace("{prompt}", positive), n + negative
|
| 233 |
-
|
| 234 |
|
| 235 |
examples = [
|
| 236 |
"a beautiful woman with blonde hair and blue eyes",
|
|
@@ -269,15 +220,6 @@ with gr.Blocks(css=css, theme=theme, fill_width= False) as app:
|
|
| 269 |
with gr.Row():
|
| 270 |
sampler = gr.Dropdown(value="DPM++ S", show_label=True, label="Sampling Method:", choices=[
|
| 271 |
"DPM++ 2M Karras", "DPM++ 2S a Karras", "DPM2 a Karras", "DPM2 Karras", "DPM++ SDE Karras", "DEIS", "LMS", "DPM Adaptive", "DPM++ 2M", "DPM2 Ancestral", "DPM++ S", "DPM++ SDE", "DDPM", "DPM Fast", "dpmpp_2s_ancestral", "Euler", "Euler CFG PP", "Euler a", "Euler Ancestral", "Euler+beta", "Heun", "Heun PP2", "DDIM", "LMS Karras", "PLMS", "UniPC", "UniPC BH2"])
|
| 272 |
-
with gr.Row(visible=True):
|
| 273 |
-
style_selection = gr.Radio(
|
| 274 |
-
show_label=True,
|
| 275 |
-
container=True,
|
| 276 |
-
interactive=True,
|
| 277 |
-
choices=STYLE_NAMES,
|
| 278 |
-
value=DEFAULT_STYLE_NAME,
|
| 279 |
-
label="Image Style",
|
| 280 |
-
)
|
| 281 |
with gr.Row():
|
| 282 |
steps = gr.Slider(show_label=True, label="Sampling Steps:", minimum=1, maximum=50, value=35, step=1)
|
| 283 |
with gr.Row():
|
|
@@ -295,7 +237,7 @@ with gr.Blocks(css=css, theme=theme, fill_width= False) as app:
|
|
| 295 |
with gr.Column(scale=0):
|
| 296 |
image_output = gr.Image(show_download_button=True, interactive=False, label='Generated Image 🌄', show_share_button=False, show_fullscreen_button=True, format="png", elem_id="gallery")
|
| 297 |
|
| 298 |
-
text_button.click(query, inputs=[prompt, negative_prompt,
|
| 299 |
clear_prompt =gr.Button("Clear 🗑️",variant="primary", elem_id="clear_button")
|
| 300 |
clear_prompt.click(lambda: (None, None), None, [prompt, image_output], queue=False, show_api=False)
|
| 301 |
|
|
|
|
| 12 |
from io import BytesIO
|
| 13 |
import base64
|
| 14 |
import re
|
|
|
|
| 15 |
from gradio_client import Client
|
| 16 |
from fake_useragent import UserAgent
|
| 17 |
import random
|
|
|
|
| 21 |
app = FastAPI()
|
| 22 |
@app.get("/")
|
| 23 |
|
| 24 |
+
def query(prompt, negative_prompt, task, steps=35, sampler="DPM++ 2M Karras", cfg_scale=7, seed=-1, width=896, height=1152):
|
| 25 |
+
result = {prompt:"prompt", negative_prompt:"negative_prompt", task:"task", steps:"steps", sampler:"sampler", cfg_scale:"cfg_scale", width:"width" , height:"height" }
|
| 26 |
print(result)
|
| 27 |
try:
|
| 28 |
language = detect(prompt)
|
|
|
|
| 181 |
img = Image.open(BytesIO(response2.content))
|
| 182 |
return img
|
| 183 |
|
|
|
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
examples = [
|
| 187 |
"a beautiful woman with blonde hair and blue eyes",
|
|
|
|
| 220 |
with gr.Row():
|
| 221 |
sampler = gr.Dropdown(value="DPM++ S", show_label=True, label="Sampling Method:", choices=[
|
| 222 |
"DPM++ 2M Karras", "DPM++ 2S a Karras", "DPM2 a Karras", "DPM2 Karras", "DPM++ SDE Karras", "DEIS", "LMS", "DPM Adaptive", "DPM++ 2M", "DPM2 Ancestral", "DPM++ S", "DPM++ SDE", "DDPM", "DPM Fast", "dpmpp_2s_ancestral", "Euler", "Euler CFG PP", "Euler a", "Euler Ancestral", "Euler+beta", "Heun", "Heun PP2", "DDIM", "LMS Karras", "PLMS", "UniPC", "UniPC BH2"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
with gr.Row():
|
| 224 |
steps = gr.Slider(show_label=True, label="Sampling Steps:", minimum=1, maximum=50, value=35, step=1)
|
| 225 |
with gr.Row():
|
|
|
|
| 237 |
with gr.Column(scale=0):
|
| 238 |
image_output = gr.Image(show_download_button=True, interactive=False, label='Generated Image 🌄', show_share_button=False, show_fullscreen_button=True, format="png", elem_id="gallery")
|
| 239 |
|
| 240 |
+
text_button.click(query, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed, width, height], outputs=image_output, concurrency_limit=48)
|
| 241 |
clear_prompt =gr.Button("Clear 🗑️",variant="primary", elem_id="clear_button")
|
| 242 |
clear_prompt.click(lambda: (None, None), None, [prompt, image_output], queue=False, show_api=False)
|
| 243 |
|