Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 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")
|
|
@@ -12,7 +14,7 @@ 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=
|
| 16 |
api_name="/stream_chat"
|
| 17 |
)
|
| 18 |
return caption
|
|
@@ -29,7 +31,9 @@ def generate_image_from_caption(caption):
|
|
| 29 |
num_inference_steps=28,
|
| 30 |
api_name="/infer"
|
| 31 |
)
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Main function to handle the upload and generate images and captions in a loop
|
| 35 |
def process_image(image, iterations):
|
|
@@ -48,7 +52,7 @@ def process_image(image, iterations):
|
|
| 48 |
generated_images.append(new_image)
|
| 49 |
|
| 50 |
# Set the newly generated image as the current image for the next iteration
|
| 51 |
-
current_image =
|
| 52 |
|
| 53 |
return generated_images, captions
|
| 54 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_client import Client, handle_file
|
| 3 |
from PIL import Image
|
| 4 |
import tempfile
|
| 5 |
+
import requests
|
| 6 |
+
from io import BytesIO
|
| 7 |
|
| 8 |
# Initialize the Hugging Face API clients
|
| 9 |
captioning_client = Client("fancyfeast/joy-caption-pre-alpha")
|
|
|
|
| 14 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
| 15 |
image.save(temp_file.name)
|
| 16 |
caption = captioning_client.predict(
|
| 17 |
+
input_image=handle_file(temp_file.name),
|
| 18 |
api_name="/stream_chat"
|
| 19 |
)
|
| 20 |
return caption
|
|
|
|
| 31 |
num_inference_steps=28,
|
| 32 |
api_name="/infer"
|
| 33 |
)
|
| 34 |
+
image_url = image[0] # Assuming the API returns a URL to the image
|
| 35 |
+
response = requests.get(image_url)
|
| 36 |
+
return Image.open(BytesIO(response.content))
|
| 37 |
|
| 38 |
# Main function to handle the upload and generate images and captions in a loop
|
| 39 |
def process_image(image, iterations):
|
|
|
|
| 52 |
generated_images.append(new_image)
|
| 53 |
|
| 54 |
# Set the newly generated image as the current image for the next iteration
|
| 55 |
+
current_image = new_image
|
| 56 |
|
| 57 |
return generated_images, captions
|
| 58 |
|