Fraser commited on
Commit
571e7a2
·
1 Parent(s): f928396
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -256,7 +256,7 @@ class PicletGeneratorService:
256
  FLUX_SPACE = "black-forest-labs/FLUX.1-schnell"
257
 
258
  @staticmethod
259
- async def generate_enhanced_caption(image_path: str, hf_token: str) -> str:
260
  """Generate detailed image description using JoyCaption
261
 
262
  Args:
@@ -271,7 +271,7 @@ class PicletGeneratorService:
271
  )
272
 
273
  print(f"Generating caption for image...")
274
- result = await client.predict(
275
  "/stream_chat",
276
  handle_file(image_path), # Wrap path so client uploads file
277
  "Descriptive", # caption_type
@@ -292,7 +292,7 @@ class PicletGeneratorService:
292
  raise Exception(f"Caption generation failed: {str(e)}")
293
 
294
  @staticmethod
295
- async def generate_text_with_gpt(prompt: str, hf_token: str) -> str:
296
  """Generate text using GPT-OSS-120B"""
297
  try:
298
  print(f"Connecting to GPT-OSS space...")
@@ -302,7 +302,7 @@ class PicletGeneratorService:
302
  )
303
 
304
  print(f"Generating text...")
305
- result = await client.predict(
306
  "/chat",
307
  prompt, # message
308
  [], # history
@@ -331,7 +331,7 @@ class PicletGeneratorService:
331
  raise Exception(f"Text generation failed: {str(e)}")
332
 
333
  @staticmethod
334
- async def generate_piclet_concept(caption: str, hf_token: str) -> dict:
335
  """
336
  Generate complete Piclet concept from image caption
337
  Returns parsed concept with object name, variation, stats, etc.
@@ -386,7 +386,7 @@ CRITICAL RULES:
386
  - Monster Description must describe the CREATURE with references to the specific object's features
387
  - Primary Type must match the object category (machina for electronics, structure for buildings, etc.)"""
388
 
389
- response_text = await PicletGeneratorService.generate_text_with_gpt(concept_prompt, hf_token)
390
 
391
  # Parse the concept
392
  return PicletGeneratorService.parse_concept(response_text)
@@ -471,7 +471,7 @@ CRITICAL RULES:
471
  }
472
 
473
  @staticmethod
474
- async def generate_piclet_image(image_prompt: str, tier: str, hf_token: str) -> dict:
475
  """Generate Piclet image using Flux"""
476
  try:
477
  print(f"Connecting to Flux space...")
@@ -490,7 +490,7 @@ CRITICAL RULES:
490
  full_prompt = f"{image_prompt}\nNow generate an Pokémon Anime image of the monster in an idle pose with a plain dark-grey background. This is a {tier} tier monster with a {tier_descriptions.get(tier, tier_descriptions['medium'])}. The monster should not be attacking or in motion. The full monster must be visible within the frame."
491
 
492
  print(f"Generating image with prompt: {full_prompt[:100]}...")
493
- result = await client.predict(
494
  "/infer",
495
  full_prompt, # prompt
496
  0, # seed
@@ -784,7 +784,7 @@ def increment_scan_count(piclet_id: str, object_name: str) -> dict:
784
  "error": str(e)
785
  }
786
 
787
- async def generate_piclet(image, hf_token: str) -> dict:
788
  """
789
  Complete Piclet generation workflow - single endpoint
790
  Takes user's image and hf_token, returns generated Piclet with discovery status
@@ -821,11 +821,11 @@ async def generate_piclet(image, hf_token: str) -> dict:
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...")
828
- concept_data = await PicletGeneratorService.generate_piclet_concept(caption, hf_token)
829
 
830
  object_name = concept_data['objectName']
831
  attributes = concept_data['attributes']
@@ -835,7 +835,7 @@ async def generate_piclet(image, hf_token: str) -> dict:
835
 
836
  # Step 3: Generate image
837
  print("Step 3/5: Generating Piclet image...")
838
- image_result = await PicletGeneratorService.generate_piclet_image(
839
  image_prompt,
840
  stats['tier'],
841
  hf_token
 
256
  FLUX_SPACE = "black-forest-labs/FLUX.1-schnell"
257
 
258
  @staticmethod
259
+ def generate_enhanced_caption(image_path: str, hf_token: str) -> str:
260
  """Generate detailed image description using JoyCaption
261
 
262
  Args:
 
271
  )
272
 
273
  print(f"Generating caption for image...")
274
+ result = client.predict(
275
  "/stream_chat",
276
  handle_file(image_path), # Wrap path so client uploads file
277
  "Descriptive", # caption_type
 
292
  raise Exception(f"Caption generation failed: {str(e)}")
293
 
294
  @staticmethod
295
+ def generate_text_with_gpt(prompt: str, hf_token: str) -> str:
296
  """Generate text using GPT-OSS-120B"""
297
  try:
298
  print(f"Connecting to GPT-OSS space...")
 
302
  )
303
 
304
  print(f"Generating text...")
305
+ result = client.predict(
306
  "/chat",
307
  prompt, # message
308
  [], # history
 
331
  raise Exception(f"Text generation failed: {str(e)}")
332
 
333
  @staticmethod
334
+ def generate_piclet_concept(caption: str, hf_token: str) -> dict:
335
  """
336
  Generate complete Piclet concept from image caption
337
  Returns parsed concept with object name, variation, stats, etc.
 
386
  - Monster Description must describe the CREATURE with references to the specific object's features
387
  - Primary Type must match the object category (machina for electronics, structure for buildings, etc.)"""
388
 
389
+ response_text = PicletGeneratorService.generate_text_with_gpt(concept_prompt, hf_token)
390
 
391
  # Parse the concept
392
  return PicletGeneratorService.parse_concept(response_text)
 
471
  }
472
 
473
  @staticmethod
474
+ def generate_piclet_image(image_prompt: str, tier: str, hf_token: str) -> dict:
475
  """Generate Piclet image using Flux"""
476
  try:
477
  print(f"Connecting to Flux space...")
 
490
  full_prompt = f"{image_prompt}\nNow generate an Pokémon Anime image of the monster in an idle pose with a plain dark-grey background. This is a {tier} tier monster with a {tier_descriptions.get(tier, tier_descriptions['medium'])}. The monster should not be attacking or in motion. The full monster must be visible within the frame."
491
 
492
  print(f"Generating image with prompt: {full_prompt[:100]}...")
493
+ result = client.predict(
494
  "/infer",
495
  full_prompt, # prompt
496
  0, # seed
 
784
  "error": str(e)
785
  }
786
 
787
+ def generate_piclet(image, hf_token: str) -> dict:
788
  """
789
  Complete Piclet generation workflow - single endpoint
790
  Takes user's image and hf_token, returns generated Piclet with discovery status
 
821
 
822
  # Step 1: Generate caption
823
  print("Step 1/5: Generating image caption...")
824
+ caption = PicletGeneratorService.generate_enhanced_caption(image_path, hf_token)
825
 
826
  # Step 2: Generate concept
827
  print("Step 2/5: Generating Piclet concept...")
828
+ concept_data = PicletGeneratorService.generate_piclet_concept(caption, hf_token)
829
 
830
  object_name = concept_data['objectName']
831
  attributes = concept_data['attributes']
 
835
 
836
  # Step 3: Generate image
837
  print("Step 3/5: Generating Piclet image...")
838
+ image_result = PicletGeneratorService.generate_piclet_image(
839
  image_prompt,
840
  stats['tier'],
841
  hf_token