Jonny001 commited on
Commit
5198cff
1 Parent(s): 4199bf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -5
app.py CHANGED
@@ -2,19 +2,31 @@ import gradio as gr
2
  import random
3
  import os
4
 
5
- # model = gr.load("models/prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA") # <-- This model is also working
 
 
 
 
 
 
 
 
 
 
 
 
6
  model = gr.load("models/Purz/face-projection")
7
 
8
- def generate_image(text, seed, width, height, guidance_scale, num_inference_steps):
9
  if seed is not None:
10
  random.seed(seed)
11
 
12
  if text in [example[0] for example in examples]:
13
  print(f"Using example: {text}")
14
 
15
- result_image = model(text)
16
 
17
- print(f"Width: {width}, Height: {height}, Guidance Scale: {guidance_scale}, Inference Steps: {num_inference_steps}")
18
 
19
  return result_image
20
 
@@ -43,6 +55,15 @@ interface = gr.Interface(
43
  gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024),
44
  gr.Slider(label="Guidance Scale", minimum=0.1, maximum=20.0, step=0.1, value=3.0),
45
  gr.Slider(label="Number of inference steps", minimum=1, maximum=40, step=1, value=28),
 
 
 
 
 
 
 
 
 
46
  ],
47
  outputs=gr.Image(label="Generated Image"),
48
  examples=examples,
@@ -50,4 +71,17 @@ interface = gr.Interface(
50
  description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
51
  )
52
 
53
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import random
3
  import os
4
 
5
+
6
+ default_negative_prompt = (
7
+ "Extra limbs, Extra fingers or toes, Disfigured face, Distorted hands, Mutated body parts, "
8
+ "Missing limbs, Asymmetrical features, Blurry face, Poor anatomy, Incorrect proportions, Crooked eyes, "
9
+ "Deformed hands or fingers, Double face, Unrealistic skin texture, Overly smooth skin, Poor lighting, "
10
+ "Cartoonish appearance, Plastic look, Grainy, Unnatural expressions, Crossed eyes, Mutated clothing, "
11
+ "Artifacts, Uncanny valley, Doll-like features, Bad symmetry, Uneven skin tones, Extra teeth, "
12
+ "Unrealistic hair texture, Dark shadows on face, Overexposed face, Cluttered background, Text, watermark, "
13
+ "or signature, Over-processed, Low quality, Blurry, Low resolution, Pixelated, Oversaturated, Too dark, Overexposed, Poor lighting, "
14
+ "Unclear, Text or watermark, Distorted faces, Extra limbs or fingers, Disfigured, Grainy, Overly stylized, Cartoonish, "
15
+ "Unrealistic anatomy, Bad proportions, Unrealistic colors, Artificial look, Background noise, Unwanted objects, Repetitive patterns, Artifacting, Abstract shapes, Out of focus"
16
+ )
17
+
18
  model = gr.load("models/Purz/face-projection")
19
 
20
+ def generate_image(text, seed, width, height, guidance_scale, num_inference_steps, negative_prompt):
21
  if seed is not None:
22
  random.seed(seed)
23
 
24
  if text in [example[0] for example in examples]:
25
  print(f"Using example: {text}")
26
 
27
+ result_image = model(text, negative_prompt=negative_prompt)
28
 
29
+ print(f"Width: {width}, Height: {height}, Guidance Scale: {guidance_scale}, Inference Steps: {num_inference_steps}, Negative Prompt: {negative_prompt}")
30
 
31
  return result_image
32
 
 
55
  gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024),
56
  gr.Slider(label="Guidance Scale", minimum=0.1, maximum=20.0, step=0.1, value=3.0),
57
  gr.Slider(label="Number of inference steps", minimum=1, maximum=40, step=1, value=28),
58
+ gr.Dropdown(
59
+ label="Negative Prompt",
60
+ choices=[
61
+ "Default Negative Prompt",
62
+ "None",
63
+ ],
64
+ value="Default Negative Prompt",
65
+ description="Choose a negative prompt to apply to the image generation."
66
+ ),
67
  ],
68
  outputs=gr.Image(label="Generated Image"),
69
  examples=examples,
 
71
  description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
72
  )
73
 
74
+ def get_negative_prompt(negative_prompt_choice):
75
+ if negative_prompt_choice == "Default Negative Prompt":
76
+ return default_negative_prompt
77
+ else:
78
+ return ""
79
+
80
+
81
+ def generate_image_with_negative_prompt(text, seed, width, height, guidance_scale, num_inference_steps, negative_prompt_choice):
82
+ negative_prompt = get_negative_prompt(negative_prompt_choice)
83
+ return generate_image(text, seed, width, height, guidance_scale, num_inference_steps, negative_prompt)
84
+
85
+ interface.fn = generate_image_with_negative_prompt
86
+
87
+ interface.launch()