Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,14 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
-
import base64
|
| 6 |
|
| 7 |
# Initialize the Inference Client
|
| 8 |
client = InferenceClient()
|
| 9 |
|
| 10 |
# Function to handle the image generation
|
| 11 |
-
def generate_image(
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
image = Image.open(io.BytesIO(image_data))
|
| 15 |
|
| 16 |
# Generate image using the InferenceClient
|
| 17 |
generated_image = client.image_to_image(image, prompt=prompt)
|
|
@@ -22,16 +20,16 @@ def generate_image(base64_image, prompt):
|
|
| 22 |
img_byte_arr.seek(0) # Move the cursor to the beginning
|
| 23 |
|
| 24 |
# Return the generated image
|
| 25 |
-
return
|
| 26 |
|
| 27 |
# Create Gradio interface
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=generate_image,
|
| 30 |
inputs=[
|
| 31 |
-
gr.inputs.Image(type="
|
| 32 |
gr.inputs.Textbox(label="Prompt") # Textbox for the prompt
|
| 33 |
],
|
| 34 |
-
outputs=gr.outputs.Image(type="
|
| 35 |
title="Image Generation with Hugging Face",
|
| 36 |
description="Upload an image and provide a prompt to generate a new image."
|
| 37 |
)
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
|
|
|
| 5 |
|
| 6 |
# Initialize the Inference Client
|
| 7 |
client = InferenceClient()
|
| 8 |
|
| 9 |
# Function to handle the image generation
|
| 10 |
+
def generate_image(image, prompt):
|
| 11 |
+
# Open the uploaded image
|
| 12 |
+
image = Image.open(image)
|
|
|
|
| 13 |
|
| 14 |
# Generate image using the InferenceClient
|
| 15 |
generated_image = client.image_to_image(image, prompt=prompt)
|
|
|
|
| 20 |
img_byte_arr.seek(0) # Move the cursor to the beginning
|
| 21 |
|
| 22 |
# Return the generated image
|
| 23 |
+
return generated_image
|
| 24 |
|
| 25 |
# Create Gradio interface
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=generate_image,
|
| 28 |
inputs=[
|
| 29 |
+
gr.inputs.Image(type="file", label="Input Image"), # File input for uploaded image
|
| 30 |
gr.inputs.Textbox(label="Prompt") # Textbox for the prompt
|
| 31 |
],
|
| 32 |
+
outputs=gr.outputs.Image(type="pil", label="Generated Image"), # Output as PIL image
|
| 33 |
title="Image Generation with Hugging Face",
|
| 34 |
description="Upload an image and provide a prompt to generate a new image."
|
| 35 |
)
|