File size: 1,274 Bytes
ef7e565
3dac59f
 
 
2eaf831
a0132bf
 
 
8aec2c6
 
 
 
 
 
 
 
 
 
 
 
a0132bf
9bd009f
 
2eaf831
 
a0132bf
2eaf831
a0132bf
8aec2c6
032fd3e
a0132bf
032fd3e
a0132bf
 
2eaf831
 
bb1b268
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
import gradio as gr
from gradio_client import Client, file
import tempfile
import os

# Initialize the client
client = Client("radames/Enhance-This-HiDiffusion-SDXL")

# Custom preprocessing function to save uploaded image to a temporary file
def preprocess_image(image):
    # Create a temporary directory
    temp_dir = tempfile.mkdtemp()
    # Save the image to a temporary file
    image_path = os.path.join(temp_dir, "input_image.jpg")
    image.save(image_path)
    return image_path

def enhance_image(image, prompt):
    # Preprocess the image
    image_path = preprocess_image(image)
    # Use the client to predict the result
    (padded_image, image_out), padded_image, anyline_image = client.predict(file(image_path), prompt, api_name="/predict")
    return image_out

# Create the Gradio interface
iface = gr.Interface(
    fn=enhance_image,
    inputs=[
        gr.Image(type="pil", label="Input Image"),
        gr.Textbox(lines=2, placeholder="Enter prompt here", label="Prompt")
    ],
    outputs=gr.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 interfacegradio_client.file(
iface.launch()