Spaces:
Running
Running
img path
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from gradio_client import Client
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import re
|
|
@@ -256,11 +256,11 @@ class PicletGeneratorService:
|
|
| 256 |
FLUX_SPACE = "black-forest-labs/FLUX.1-schnell"
|
| 257 |
|
| 258 |
@staticmethod
|
| 259 |
-
async def generate_enhanced_caption(
|
| 260 |
"""Generate detailed image description using JoyCaption
|
| 261 |
|
| 262 |
Args:
|
| 263 |
-
|
| 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 |
-
|
| 277 |
"Descriptive", # caption_type
|
| 278 |
"medium-length", # caption_length
|
| 279 |
[], # extra_options
|
|
@@ -816,14 +816,12 @@ 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 |
-
#
|
| 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(
|
| 827 |
|
| 828 |
# Step 2: Generate concept
|
| 829 |
print("Step 2/5: Generating Piclet concept...")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_client import Client, handle_file
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import re
|
|
|
|
| 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:
|
| 263 |
+
image_path: Path to image file
|
| 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 |
+
handle_file(image_path), # Wrap path so client uploads file
|
| 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 |
+
# Get image path from Gradio (type="filepath" gives us a string path)
|
|
|
|
| 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...")
|