Spaces:
Runtime error
Runtime error
File size: 1,218 Bytes
ef7e565 a0132bf c7a6660 2eaf831 a0132bf c7a6660 a0132bf c7a6660 a0132bf c7a6660 2eaf831 a0132bf 2eaf831 a0132bf c7a6660 a0132bf c7a6660 a0132bf 2eaf831 a0132bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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()
|