Fraser commited on
Commit
fbed94a
·
1 Parent(s): bfb6a62
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -256,11 +256,11 @@ class PicletGeneratorService:
256
  FLUX_SPACE = "black-forest-labs/FLUX.1-schnell"
257
 
258
  @staticmethod
259
- async def generate_enhanced_caption(image_data, hf_token: str) -> str:
260
  """Generate detailed image description using JoyCaption
261
 
262
  Args:
263
- image_data: PIL Image or file path
264
  hf_token: User's HuggingFace token
265
  """
266
  try:
@@ -273,7 +273,7 @@ class PicletGeneratorService:
273
  print(f"Generating caption for image...")
274
  result = await client.predict(
275
  "/stream_chat",
276
- image_data, # input_image
277
  "Descriptive", # caption_type
278
  "medium-length", # caption_length
279
  [], # extra_options
@@ -816,12 +816,14 @@ async def generate_piclet(image, hf_token: str) -> dict:
816
  # Get user profile (creates if doesn't exist)
817
  user_profile = PicletDiscoveryService.get_or_create_user_profile(user_info)
818
 
819
- # Extract image path from Gradio input (already a filepath string)
 
820
  image_path = image if isinstance(image, str) else str(image)
 
821
 
822
  # Step 1: Generate caption
823
  print("Step 1/5: Generating image caption...")
824
- caption = await PicletGeneratorService.generate_enhanced_caption(image_path, hf_token)
825
 
826
  # Step 2: Generate concept
827
  print("Step 2/5: Generating Piclet concept...")
 
256
  FLUX_SPACE = "black-forest-labs/FLUX.1-schnell"
257
 
258
  @staticmethod
259
+ async def generate_enhanced_caption(image_pil, hf_token: str) -> str:
260
  """Generate detailed image description using JoyCaption
261
 
262
  Args:
263
+ image_pil: PIL Image object
264
  hf_token: User's HuggingFace token
265
  """
266
  try:
 
273
  print(f"Generating caption for image...")
274
  result = await client.predict(
275
  "/stream_chat",
276
+ image_pil, # input_image (PIL Image)
277
  "Descriptive", # caption_type
278
  "medium-length", # caption_length
279
  [], # extra_options
 
816
  # Get user profile (creates if doesn't exist)
817
  user_profile = PicletDiscoveryService.get_or_create_user_profile(user_info)
818
 
819
+ # Load image once as PIL Image
820
+ from PIL import Image as PILImage
821
  image_path = image if isinstance(image, str) else str(image)
822
+ image_pil = PILImage.open(image_path)
823
 
824
  # Step 1: Generate caption
825
  print("Step 1/5: Generating image caption...")
826
+ caption = await PicletGeneratorService.generate_enhanced_caption(image_pil, hf_token)
827
 
828
  # Step 2: Generate concept
829
  print("Step 2/5: Generating Piclet concept...")