logo
0
0
WeChat Login
echonlab<zhangtianhao@catnips.ai>
Add Vertex AI credential support with project-relative default path

GifStudio

Commercial-grade realtime GIF generation system. Includes a LangGraph agent for orchestration, a Klein4B+BFS head-swap image editor, a GIF generation interface (TBD), and a high-performance FastAPI server.

Project Structure

src/gifstudio/ ├── __init__.py ├── __main__.py ├── cli.py # CLI entry point (run / graph / serve) ├── config.py # pydantic-settings, GIFSTUDIO_ env prefix ├── api.py # FastAPI server (uvicorn + orjson + uvloop) ├── agent/ │ ├── state.py # AgentState(MessagesState) │ ├── graph.py # LangGraph: START → router → tools → finalize → END │ ├── nodes.py # router_node, tool_node, finalize_node │ └── tools.py # @tool edit_image, @tool generate_gif ├── image_edit/ │ ├── base.py # ImageEditor ABC, ImageEditRequest/Result │ └── klein_headswap.py # Klein4B + BFS head-swap backend └── gif_gen/ └── base.py # GifGenerator ABC, GifGenRequest/Result (impl TBD)

Installation

# Install dependencies pip install langgraph langchain-core langchain-google-genai pydantic-settings \ fastapi "uvicorn[standard]" orjson python-multipart # Editable install pip install -e /home/echonlab/workspace/gifstudio

Configuration

All settings use the GIFSTUDIO_ environment variable prefix. Copy .env.example and fill in your values:

cp .env.example .env
VariableDefaultDescription
GIFSTUDIO_LLM_PROVIDERgoogleLLM provider (google or openai)
GIFSTUDIO_LLM_MODELgemini-2.0-flashModel name
GIFSTUDIO_LLM_API_KEYAPI key
GIFSTUDIO_LLM_TEMPERATURE0.0Sampling temperature
GIFSTUDIO_DEVICEcudaTorch device
GIFSTUDIO_DTYPEbfloat16Torch dtype
GIFSTUDIO_KLEIN_MODEL_DIR~/workspace/models/FLUX.2-klein-4BKlein4B model directory
GIFSTUDIO_KLEIN_LORA_PATH~/workspace/models/BFS-Best-Face-Swap/bfs_head_v1_flux-klein_4b.safetensorsBFS LoRA weights
GIFSTUDIO_FLUX2_SRC~/workspace/flux2/srcBFL source root
GIFSTUDIO_OUTPUT_DIR./outputOutput directory

Usage

CLI

# Show help gifstudio --help # Run agent with a prompt gifstudio run "swap the head in body.png with face.png" --image body.png # Print agent graph structure gifstudio graph # Start API server gifstudio serve --host 0.0.0.0 --port 8000

Also supports python -m gifstudio.

API Server

# Start gifstudio serve --port 8000 # or uvicorn gifstudio.api:app --host 0.0.0.0 --port 8000

Endpoints

MethodPathDescription
GET/healthHealth check, reports GPU load status
POST/v1/headswapHead-swap: upload body + face images
GET/v1/headswap/result/{filename}Download result image
POST/v1/gifGenerate GIF (backend TBD)

Head-swap example

curl -X POST http://localhost:8000/v1/headswap \ -F "body_image=@body.png" \ -F "face_image=@face.png" \ -F "prompt=" \ -F "seed=42" \ -F "width=512" \ -F "height=512"

Response:

{ "output_path": "output/headswap_a1b2c3d4.png", "elapsed_ms": 1234.5, "metadata": {"seed": 42, "width": 512, "height": 512} }

Performance Design

  • FastAPI + Starlette — fastest Python web framework, async-native
  • ORJSONResponse — orjson serialization (3-10x faster than stdlib json)
  • uvicorn + uvloop — C-level event loop for near-native throughput
  • ThreadPoolExecutor — GPU work offloaded so the event loop never blocks
  • Startup warmup — model loaded on server start, first request pays no loading cost

About

No description, topics, or website provided.
Language
Python87.7%
HTML12.3%