SpyCoder77 commited on
Commit
12c9a39
·
verified ·
1 Parent(s): ceeb60d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
- from gradio_client import Client, file
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
- caption = captioning_client.predict(
12
- input_image=image,
13
- api_name="/stream_chat"
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