Spaces:
Runtime error
Runtime error
import gradio as gr | |
from gradio_client import Client | |
import base64 | |
from PIL import Image | |
import io | |
# Initialize the client | |
client = Client("radames/Enhance-This-HiDiffusion-SDXL") | |
def pil_to_base64(img): | |
buffered = io.BytesIO() | |
img.save(buffered, format="PNG") | |
return base64.b64encode(buffered.getvalue()).decode('utf-8') | |
def enhance_image(image, prompt): | |
# Convert the image to base64 | |
image_base64 = pil_to_base64(image) | |
# Use the client to predict the result | |
result_base64 = client.predict(image_base64, prompt, api_name="/predict") | |
# Convert result from base64 to PIL Image | |
result_image = Image.open(io.BytesIO(base64.b64decode(result_base64))) | |
return result_image | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=enhance_image, | |
inputs=[ | |
gr.inputs.Image(type="pil", label="Input Image"), | |
gr.inputs.Textbox(lines=2, placeholder="Enter prompt here", label="Prompt") | |
], | |
outputs=gr.outputs.Image(type="pil", label="Enhanced Image"), | |
title="Image Enhancement with Text Prompt", | |
description="Upload an image and provide a text prompt to enhance the image using HiDiffusion SDXL." | |
) | |
# Launch the interface | |
iface.launch() | |