Ashrafb commited on
Commit
1f5e781
·
1 Parent(s): 9995f4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -21
app.py CHANGED
@@ -62,26 +62,46 @@ DEFAULT_IMAGE_STYLE = "Cinematic"
62
 
63
 
64
  # ... (Previous code remains unchanged)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- def send_it1(inputs, noise_level, style, proc=model_interface):
67
- global request_counter
68
- request_counter += 1
69
- timestamp = f"{time.time()}_{request_counter}"
70
- advanced_options = f"\nStyle: {style}\n"
71
- negative_prompt = " "
72
- prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}" + advanced_options + negative_prompt
73
- while queue.qsize() >= queue_threshold:
74
- time.sleep(2)
75
- queue.put(prompt_with_noise)
76
- output = proc(prompt_with_noise)
77
- return output
78
 
79
- # ... (Remaining code remains unchanged)
80
-
81
-
82
- # ... (existing code)
83
-
84
- # ... (existing code)
85
 
86
  with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{display:none !important;}",) as demo:
87
 
@@ -121,8 +141,8 @@ with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{displa
121
  output1 = gr.Image(label="", show_label=False, show_share_button=False)
122
  output2 = gr.Image(label="", show_label=False, show_share_button=False)
123
 
124
- # Adjust the click event to include the style_selection Radio component
125
- run.click(send_it1, inputs=[prompt, noise_level, style_selection, negative_prompt], outputs=[output1])
126
- run.click(send_it1, inputs=[prompt, noise_level, style_selection, negative_prompt], outputs=[output2])
127
 
128
  demo.launch(enable_queue=True, inline=True)
 
62
 
63
 
64
  # ... (Previous code remains unchanged)
65
+ def generate_txt2img(model_interface, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7, seed=None):
66
+ if image_style == "None style":
67
+ payload = {
68
+ "inputs": prompt + ", 8k",
69
+ "is_negative": is_negative,
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 == "Cinematic":
75
+ payload = {
76
+ "inputs": prompt + ", realistic, detailed, textured, skin, hair, eyes, by Alex Huguet, Mike Hill, Ian Spriggs, JaeCheol Park, Marek Denko",
77
+ "is_negative": is_negative + ", abstract, cartoon, stylized",
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 == "Digital Art":
83
+ payload = {
84
+ "inputs": prompt + ", faded , vintage , nostalgic , by Jose Villa , Elizabeth Messina , Ryan Brenizer , Jonas Peterson , Jasmine Star",
85
+ "is_negative": is_negative + ", sharp , modern , bright",
86
+ "steps": steps,
87
+ "cfg_scale": cfg_scale,
88
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
89
+ }
90
+ elif image_style == "Portrait":
91
+ payload = {
92
+ "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)",
93
+ "is_negative": is_negative,
94
+ "steps": steps,
95
+ "cfg_scale": cfg_scale,
96
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
97
+ }
98
+
99
+ image_bytes = requests.post(API_URL, headers=headers, json=payload).content
100
+ image = Image.open(io.BytesIO(image_bytes))
101
+ return image
102
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
+ # ... (Previous code remains unchanged)
 
 
 
 
 
105
 
106
  with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{display:none !important;}",) as demo:
107
 
 
141
  output1 = gr.Image(label="", show_label=False, show_share_button=False)
142
  output2 = gr.Image(label="", show_label=False, show_share_button=False)
143
 
144
+ # Adjust the click event to use generate_txt2img function
145
+ run.click(generate_txt2img, inputs=[prompt, negative_prompt, style_selection, noise_level], outputs=[output1])
146
+ run.click(generate_txt2img, inputs=[prompt, negative_prompt, style_selection, noise_level], outputs=[output2])
147
 
148
  demo.launch(enable_queue=True, inline=True)