linoyts HF staff commited on
Commit
698664c
·
verified ·
1 Parent(s): 2195218

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -3
app.py CHANGED
@@ -46,12 +46,73 @@ function refresh() {
46
  }
47
  """
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  MAX_SEED = np.iinfo(np.int32).max
50
  TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
51
  os.makedirs(TMP_DIR, exist_ok=True)
52
 
53
 
54
 
 
 
 
 
 
55
  def start_session(req: gr.Request):
56
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
57
  os.makedirs(user_dir, exist_ok=True)
@@ -78,11 +139,14 @@ def preprocess_image(image: Image.Image,
78
  Image.Image: The preprocessed image.
79
  """
80
  if prompt is not None:
 
81
  width, height = image['composite'].size
82
  ratio = np.sqrt(1024. * 1024. / (width * height))
83
  new_width, new_height = int(width * ratio), int(height * ratio)
84
  image = image['composite'].resize((new_width, new_height))
85
-
 
 
86
  image = pipe_control(
87
  prompt=prompt,
88
  negative_prompt=negative_prompt,
@@ -323,9 +387,11 @@ with gr.Blocks(delete_cache=(600, 600), js=js_func) as demo:
323
  with gr.Tab(label="Single Image", id=0) as single_image_input_tab:
324
  #image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
325
  image_prompt = image = gr.ImageEditor(type="pil", image_mode="L", crop_size=(512, 512))
326
- with gr.Row():
327
  prompt = gr.Textbox(label="Prompt")
328
- #negative_prompt = gr.Textbox(label="Negative prompt")
 
 
329
  with gr.Tab(label="Multiple Images", id=1, visible=False) as multiimage_input_tab:
330
  multiimage_prompt = gr.Gallery(label="Image Prompt", format="png", type="pil", height=300, columns=3)
331
  gr.Markdown("""
 
46
  }
47
  """
48
 
49
+ style_list = [
50
+ {
51
+ "name": "(No style)",
52
+ "prompt": "{prompt}",
53
+ "negative_prompt": "longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
54
+ },
55
+ {
56
+ "name": "Cinematic",
57
+ "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
58
+ "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
59
+ },
60
+ {
61
+ "name": "3D Model",
62
+ "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
63
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
64
+ },
65
+ {
66
+ "name": "Anime",
67
+ "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
68
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
69
+ },
70
+ {
71
+ "name": "Digital Art",
72
+ "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
73
+ "negative_prompt": "photo, photorealistic, realism, ugly",
74
+ },
75
+ {
76
+ "name": "Photographic",
77
+ "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
78
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
79
+ },
80
+ {
81
+ "name": "Pixel art",
82
+ "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
83
+ "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
84
+ },
85
+ {
86
+ "name": "Fantasy art",
87
+ "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
88
+ "negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
89
+ },
90
+ {
91
+ "name": "Neonpunk",
92
+ "prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
93
+ "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
94
+ },
95
+ {
96
+ "name": "Manga",
97
+ "prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
98
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
99
+ },
100
+ ]
101
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
102
+ STYLE_NAMES = list(styles.keys())
103
+ DEFAULT_STYLE_NAME = "(No style)"
104
+
105
  MAX_SEED = np.iinfo(np.int32).max
106
  TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
107
  os.makedirs(TMP_DIR, exist_ok=True)
108
 
109
 
110
 
111
+ def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
112
+ p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
113
+ return p.replace("{prompt}", positive), n + negative
114
+
115
+
116
  def start_session(req: gr.Request):
117
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
118
  os.makedirs(user_dir, exist_ok=True)
 
139
  Image.Image: The preprocessed image.
140
  """
141
  if prompt is not None:
142
+
143
  width, height = image['composite'].size
144
  ratio = np.sqrt(1024. * 1024. / (width * height))
145
  new_width, new_height = int(width * ratio), int(height * ratio)
146
  image = image['composite'].resize((new_width, new_height))
147
+
148
+ prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
149
+
150
  image = pipe_control(
151
  prompt=prompt,
152
  negative_prompt=negative_prompt,
 
387
  with gr.Tab(label="Single Image", id=0) as single_image_input_tab:
388
  #image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
389
  image_prompt = image = gr.ImageEditor(type="pil", image_mode="L", crop_size=(512, 512))
390
+ with gr.Column():
391
  prompt = gr.Textbox(label="Prompt")
392
+ with gr.Row():
393
+ style = gr.Dropdown(label="Style", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
394
+ negative_prompt = gr.Textbox(label="Negative prompt")
395
  with gr.Tab(label="Multiple Images", id=1, visible=False) as multiimage_input_tab:
396
  multiimage_prompt = gr.Gallery(label="Image Prompt", format="png", type="pil", height=300, columns=3)
397
  gr.Markdown("""