Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
|
|
|
|
|
|
3 |
|
4 |
# Initialize the client
|
5 |
client = Client("radames/Enhance-This-HiDiffusion-SDXL")
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
def enhance_image(image, prompt):
|
|
|
|
|
|
|
8 |
# Use the client to predict the result
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
# Create the Gradio interface
|
13 |
iface = gr.Interface(
|
14 |
fn=enhance_image,
|
15 |
inputs=[
|
16 |
-
gr.Image(type="pil", label="Input Image"),
|
17 |
-
gr.Textbox(lines=2, placeholder="Enter prompt here", label="Prompt")
|
18 |
],
|
19 |
-
outputs=gr.Image(type="pil", label="Enhanced Image"),
|
20 |
title="Image Enhancement with Text Prompt",
|
21 |
description="Upload an image and provide a text prompt to enhance the image using HiDiffusion SDXL."
|
22 |
)
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
+
import base64
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
|
7 |
# Initialize the client
|
8 |
client = Client("radames/Enhance-This-HiDiffusion-SDXL")
|
9 |
|
10 |
+
def pil_to_base64(img):
|
11 |
+
buffered = io.BytesIO()
|
12 |
+
img.save(buffered, format="PNG")
|
13 |
+
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
14 |
+
|
15 |
def enhance_image(image, prompt):
|
16 |
+
# Convert the image to base64
|
17 |
+
image_base64 = pil_to_base64(image)
|
18 |
+
|
19 |
# Use the client to predict the result
|
20 |
+
result_base64 = client.predict(image_base64, prompt, api_name="/predict")
|
21 |
+
|
22 |
+
# Convert result from base64 to PIL Image
|
23 |
+
result_image = Image.open(io.BytesIO(base64.b64decode(result_base64)))
|
24 |
+
return result_image
|
25 |
|
26 |
# Create the Gradio interface
|
27 |
iface = gr.Interface(
|
28 |
fn=enhance_image,
|
29 |
inputs=[
|
30 |
+
gr.inputs.Image(type="pil", label="Input Image"),
|
31 |
+
gr.inputs.Textbox(lines=2, placeholder="Enter prompt here", label="Prompt")
|
32 |
],
|
33 |
+
outputs=gr.outputs.Image(type="pil", label="Enhanced Image"),
|
34 |
title="Image Enhancement with Text Prompt",
|
35 |
description="Upload an image and provide a text prompt to enhance the image using HiDiffusion SDXL."
|
36 |
)
|