-
Notifications
You must be signed in to change notification settings - Fork 687
Add face swapper skill #598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wildanmuhib
wants to merge
4
commits into
crestalnetwork:main
Choose a base branch
from
wildanmuhib:face-swapper-skill
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "intentkit" | |
version = "0.5.0" | ||
description = "Intent-based AI Agent Platform" | ||
authors = [{ name = "Ruihua", email = "[email protected]" }] | ||
requires-python = "==3.12.*" | ||
requires-python = ">=3.12,<3.14" | ||
readme = "README.md" | ||
dependencies = [ | ||
"langgraph (>=0.4.3,<0.5.0)", | ||
|
@@ -90,3 +90,6 @@ build-backend = "hatchling.build" | |
|
||
[tool.ruff.lint] | ||
extend-select = ["I"] | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["intentkit"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# intentkit/skills/face_swapper/__init__.py | ||
|
||
from typing import TypedDict | ||
from abstracts.skill import SkillStoreABC | ||
from skills.base import SkillConfig, SkillState | ||
from skills.face_swapper.base import FaceSwapperBaseTool | ||
from skills.face_swapper.face_swap import FaceSwapTool | ||
|
||
_cache: dict[str, FaceSwapperBaseTool] = {} | ||
|
||
class SkillStates(TypedDict): | ||
face_swap: SkillState | ||
|
||
class Config(SkillConfig): | ||
"""Configuration for face swap skills.""" | ||
states: SkillStates | ||
|
||
async def get_skills( | ||
config: "Config", | ||
is_private: bool, | ||
store: SkillStoreABC, | ||
**_, | ||
) -> list[FaceSwapperBaseTool]: | ||
available_skills = [] | ||
|
||
for skill_name, state in config["states"].items(): | ||
if state == "disabled": | ||
continue | ||
elif state == "public" or (state == "private" and is_private): | ||
available_skills.append(skill_name) | ||
|
||
return [get_face_swapper_skill(name, store) for name in available_skills] | ||
|
||
def get_face_swapper_skill(name: str, store: SkillStoreABC) -> FaceSwapperBaseTool: | ||
if name == "face_swap": | ||
if name not in _cache: | ||
_cache[name] = FaceSwapTool(skill_store=store) | ||
return _cache[name] | ||
else: | ||
raise ValueError(f"Unknown face swap skill: {name}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# intentkit/skills/face_swapper/base.py | ||
|
||
from typing import Type | ||
from pydantic import BaseModel, Field | ||
from abstracts.skill import SkillStoreABC | ||
from skills.base import IntentKitSkill | ||
|
||
class FaceSwapperBaseTool(IntentKitSkill): | ||
"""Base class for face swap tools.""" | ||
|
||
name: str = Field(description="The name of the tool") | ||
description: str = Field(description="A description of what the tool does") | ||
args_schema: Type[BaseModel] | ||
skill_store: SkillStoreABC = Field(description="The skill store for persisting data") | ||
|
||
@property | ||
def category(self) -> str: | ||
return "face_swapper" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# intentkit/skills/face_swapper/face_swap.py | ||
|
||
from typing import Type | ||
from pydantic import BaseModel, Field | ||
import httpx | ||
|
||
from skills.face_swapper.base import FaceSwapperBaseTool | ||
|
||
|
||
class FaceSwapInput(BaseModel): | ||
"""Input untuk alat face swap.""" | ||
|
||
source_image_url: str = Field(description="URL gambar wajah sumber") | ||
target_image_url: str = Field(description="URL gambar target") | ||
api_url: str = Field(description="Endpoint API face swap pihak ketiga") | ||
api_key: str = Field(description="API key untuk autentikasi dengan penyedia API") | ||
|
||
|
||
class FaceSwapTool(FaceSwapperBaseTool): | ||
"""Alat untuk melakukan face swap dengan API pihak ketiga.""" | ||
|
||
name: str = "face_swap" | ||
description: str = ( | ||
"Swap wajah dari satu gambar ke gambar lain menggunakan layanan API eksternal." | ||
) | ||
args_schema: Type[BaseModel] = FaceSwapInput | ||
|
||
async def _arun( | ||
self, | ||
source_image_url: str, | ||
target_image_url: str, | ||
api_url: str, | ||
api_key: str, | ||
**kwargs, | ||
) -> str: | ||
payload = { | ||
"source_image": source_image_url, | ||
"target_image": target_image_url, | ||
} | ||
headers = { | ||
"Authorization": f"Bearer {api_key}" | ||
} | ||
|
||
async with httpx.AsyncClient() as client: | ||
response = await client.post(api_url, json=payload, headers=headers) | ||
|
||
if response.status_code == 200: | ||
return response.json().get("result_url", "Success, but no result_url found.") | ||
else: | ||
return f"Error: {response.status_code} - {response.text}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"title": "Face Swapper Skills", | ||
"description": "Configuration schema for face swapper tools", | ||
"properties": { | ||
"states": { | ||
"type": "object", | ||
"properties": { | ||
"face_swap": { | ||
"type": "string", | ||
"title": "Face Swap Tool", | ||
"enum": ["disabled", "public", "private"], | ||
"description": "State of the face_swap tool" | ||
} | ||
}, | ||
"description": "States for each face swapper tool" | ||
} | ||
}, | ||
"required": ["states"], | ||
"additionalProperties": true | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
api_url
andapi_key
should not be included as_arun
parameters.You must integrate the actual third-party service directly, unless you're implementing the face-swap logic within your own skill code.
Please follow the skill development guidelines when contributing to the project.
You may also refer to existing skills to see how third-party services are properly integrated.