Skip to content
Open

V8 #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions backend/app/controllers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
from app.services.image import ImageService
from app.services.project import ProjectService
from app.utils.database import db_client
from app.utils.storage import (
download_and_upload_image_from_url,
save_image_pair_to_db,
upload_image_to_storage,
)
from app.utils.storage import (download_and_upload_image_from_url,
save_image_pair_to_db, upload_image_to_storage)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -178,22 +175,26 @@ async def generate_image(
)
log.info("Image generation completed successfully")

# Add background task to generate and save project icon (on first generation)
background_tasks.add_task(
generate_and_save_project_icon,
authorization=authorization,
project_id=input.project_id,
)

# Add background task to save images to database
background_tasks.add_task(
save_images_to_database,
authorization=authorization,
project_id=input.project_id,
input_image_data=input.image_data,
output_image_data=response.image_data,
prompt_text=input.prompt,
)
# Only add background tasks if save_data is True
if input.save_data:
# Add background task to generate and save project icon (on first generation)
background_tasks.add_task(
generate_and_save_project_icon,
authorization=authorization,
project_id=input.project_id,
)

# Add background task to save images to database
background_tasks.add_task(
save_images_to_database,
authorization=authorization,
project_id=input.project_id,
input_image_data=input.image_data,
output_image_data=response.image_data,
prompt_text=input.prompt,
)
else:
log.info("Skipping save operations as save_data is False")

return response
except ValueError as e:
Expand Down
11 changes: 3 additions & 8 deletions backend/app/controllers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

from fastapi import APIRouter, Header, HTTPException

from app.models.project import (
IconGenerationRequest,
IconGenerationResponse,
Project,
ProjectCreateRequest,
ProjectListResponse,
ProjectUpdateRequest,
)
from app.models.project import (IconGenerationRequest, IconGenerationResponse,
Project, ProjectCreateRequest,
ProjectListResponse, ProjectUpdateRequest)
from app.services.project import ProjectService
from app.utils.database import db_client

Expand Down
9 changes: 7 additions & 2 deletions backend/app/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ class ImageGenerationRequest(BaseModel):
default=None,
description="Optional base64 encoded image data to use as input for image generation.",
)
project_id: str = Field(
description="The project ID to associate with this image pair."
project_id: Optional[str] = Field(
default=None,
description="Optional project ID to associate with this image pair. Required when save_data is True.",
)
type: Literal["generate", "edit"] = Field(
default="generate",
description="The type of operation: 'generate' for new images or 'edit' for modifying existing images.",
)
save_data: bool = Field(
default=True,
description="Whether to save the generated images to database and generate project icon. Default is True.",
)


class ImageGenerationResponse(BaseModel):
Expand Down
13 changes: 5 additions & 8 deletions backend/app/services/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
from openai import OpenAI
from supabase._async.client import AsyncClient as Client

from app.models.project import (
IconGenerationRequest,
IconGenerationResponse,
Project,
ProjectCreateRequest,
ProjectUpdateRequest,
)
from app.models.project import (IconGenerationRequest, IconGenerationResponse,
Project, ProjectCreateRequest,
ProjectUpdateRequest)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -250,7 +246,8 @@ async def generate_3d_icon(

try:
# Construct the full prompt with style modifiers
full_prompt = f"The following is a text prompt or a conversation about a 2 or 3 word topic: {request.prompt}, Draw a 3D smooth icon png with the following style: {request.style}. Also make sure you don't include text in the image."
# Keep it simple and direct for better AI understanding
full_prompt = f"A clean 3D icon representing '{request.prompt}'. Style: {request.style}. No text or labels in the image."

# Define callback to log queue updates
def on_queue_update(update):
Expand Down
1 change: 0 additions & 1 deletion backend/app/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import uuid

from supabase import AsyncClientOptions

# from supabase import AsyncClientOptions
from supabase._async.client import AsyncClient as Client
from supabase._async.client import create_client
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/actions/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
export interface GenerateImageRequest {
prompt: string;
image_data?: string | null;
project_id: string;
project_id?: string;
type: 'generate' | 'edit';
save_data?: boolean;
}

export interface GenerateImageResponse {
Expand Down
Loading
Loading