Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from gradio_client import Client
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
|
| 5 |
# Initialize the Hugging Face API clients
|
| 6 |
captioning_client = Client("fancyfeast/joy-caption-pre-alpha")
|
|
@@ -8,10 +9,12 @@ generation_client = Client("black-forest-labs/FLUX.1-dev")
|
|
| 8 |
|
| 9 |
# Function to caption an image
|
| 10 |
def caption_image(image):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
return caption
|
| 16 |
|
| 17 |
# Function to generate an image from a text prompt using Hugging Face API
|
|
@@ -45,7 +48,7 @@ def process_image(image, iterations):
|
|
| 45 |
generated_images.append(new_image)
|
| 46 |
|
| 47 |
# Set the newly generated image as the current image for the next iteration
|
| 48 |
-
current_image = new_image
|
| 49 |
|
| 50 |
return generated_images, captions
|
| 51 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
from PIL import Image
|
| 4 |
+
import tempfile
|
| 5 |
|
| 6 |
# Initialize the Hugging Face API clients
|
| 7 |
captioning_client = Client("fancyfeast/joy-caption-pre-alpha")
|
|
|
|
| 9 |
|
| 10 |
# Function to caption an image
|
| 11 |
def caption_image(image):
|
| 12 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
| 13 |
+
image.save(temp_file.name)
|
| 14 |
+
caption = captioning_client.predict(
|
| 15 |
+
input_image=file(temp_file.name),
|
| 16 |
+
api_name="/stream_chat"
|
| 17 |
+
)
|
| 18 |
return caption
|
| 19 |
|
| 20 |
# Function to generate an image from a text prompt using Hugging Face API
|
|
|
|
| 48 |
generated_images.append(new_image)
|
| 49 |
|
| 50 |
# Set the newly generated image as the current image for the next iteration
|
| 51 |
+
current_image = Image.open(BytesIO(new_image)) # Convert to PIL Image
|
| 52 |
|
| 53 |
return generated_images, captions
|
| 54 |
|