Spaces:
Runtime error
Runtime error
feat: Refactor image refinement process in app.py
Browse filesThe code changes refactor the image refinement process in the `app.py` file. The `refine_image` function now uses the Hugging Face InferenceClient to handle the image-to-image transformation. This improves the efficiency and reliability of the refinement process.
app.py
CHANGED
@@ -1,26 +1,17 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
|
|
|
|
|
|
|
4 |
from gradio_imageslider import ImageSlider
|
5 |
|
6 |
stable_diffusion_xl_refiner_10 = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-refiner-1.0"
|
7 |
-
refiner_client = None
|
8 |
|
9 |
def refine_image(image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
job = refiner_client.submit(
|
14 |
-
inputs=image,
|
15 |
-
parameters={
|
16 |
-
"prompt":prompt,
|
17 |
-
"negative_prompt": negative_prompt,
|
18 |
-
"num_inference_steps": num_inference_steps,
|
19 |
-
"guidance_scale": guidance_scale,
|
20 |
-
"seed": seed,
|
21 |
-
}
|
22 |
-
)
|
23 |
-
return job.result()
|
24 |
|
25 |
with gr.Blocks() as demo:
|
26 |
image = gr.Image()
|
|
|
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()
|