Lisandro commited on
Commit
ff7e22a
·
1 Parent(s): 53df086

feat: Update image refinement process in app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -1,22 +1,34 @@
1
  import os
2
  import gradio as gr
3
-
4
  from huggingface_hub import InferenceClient
5
  client = InferenceClient()
6
-
7
  from gradio_imageslider import ImageSlider
8
 
9
- stable_diffusion_xl_refiner_10 = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-refiner-1.0"
10
-
11
- def refine_image(image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed):
12
 
13
- image = client.image_to_image(image, prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, seed=seed, model="stabilityai/stable-diffusion-xl-refiner-1.0")
 
 
 
 
 
 
 
 
 
 
14
  return image
15
 
16
  with gr.Blocks() as demo:
17
  image = gr.Image(type="filepath")
18
  prompt = gr.Textbox(lines=3, label="Prompt")
19
  negative_prompt = gr.Textbox(lines=3, label="Negative Prompt")
 
 
 
 
 
 
 
20
  num_inference_steps = gr.Slider(
21
  label="Inference steps",
22
  minimum=3,
@@ -42,7 +54,11 @@ with gr.Blocks() as demo:
42
  refine_btn = gr.Button("Refine")
43
  output = gr.Image()
44
 
45
- refine_btn.click(refine_image, inputs=[image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed], outputs=output)
 
 
 
 
46
 
47
  demo.launch()
48
 
 
1
  import os
2
  import gradio as gr
 
3
  from huggingface_hub import InferenceClient
4
  client = InferenceClient()
 
5
  from gradio_imageslider import ImageSlider
6
 
 
 
 
7
 
8
+ def refine_image(image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed, strength):
9
+ image = client.image_to_image(
10
+ image,
11
+ prompt=prompt,
12
+ negative_prompt=negative_prompt,
13
+ num_inference_steps=num_inference_steps,
14
+ guidance_scale=guidance_scale,
15
+ seed=seed,
16
+ model="stabilityai/stable-diffusion-xl-refiner-1.0",
17
+ strength=strength
18
+ )
19
  return image
20
 
21
  with gr.Blocks() as demo:
22
  image = gr.Image(type="filepath")
23
  prompt = gr.Textbox(lines=3, label="Prompt")
24
  negative_prompt = gr.Textbox(lines=3, label="Negative Prompt")
25
+ strength = gr.Slider(
26
+ label="Strength",
27
+ minimum=0,
28
+ maximum=3,
29
+ step=0.01,
30
+ value=1
31
+ )
32
  num_inference_steps = gr.Slider(
33
  label="Inference steps",
34
  minimum=3,
 
54
  refine_btn = gr.Button("Refine")
55
  output = gr.Image()
56
 
57
+ refine_btn.click(
58
+ refine_image,
59
+ inputs=[image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed, strength],
60
+ outputs=output
61
+ )
62
 
63
  demo.launch()
64