mirror of
https://github.com/vladmandic/automatic
synced 2026-09-18 16:54:33 +02:00
video: support for scripts/extensions
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
+36
-48
@@ -1,7 +1,6 @@
|
||||
from threading import Lock
|
||||
from pydantic import BaseModel, Field # pylint: disable=no-name-in-module
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.exceptions import HTTPException
|
||||
from modules.api.helpers import decode_base64_to_image, encode_pil_to_base64
|
||||
from modules import errors, shared, postprocessing
|
||||
from modules.api import models, helpers
|
||||
@@ -20,6 +19,7 @@ class ResPreprocess(BaseModel):
|
||||
model: str = Field(default='', title="Model", description="The processor model used")
|
||||
image: str = Field(default='', title="Image", description="The processed image in base64 format")
|
||||
|
||||
|
||||
class ReqMask(BaseModel):
|
||||
image: str = Field(title="Image", description="The base64 encoded image")
|
||||
type: str = Field(title="Mask type", description="Type of masking image to return")
|
||||
@@ -27,6 +27,10 @@ class ReqMask(BaseModel):
|
||||
model: str | None = Field(title="Model", description="The model to use for preprocessing")
|
||||
params: dict | None = Field(default={}, title="Settings", description="Preprocessor settings")
|
||||
|
||||
class ResMask(BaseModel):
|
||||
mask: str = Field(default='', title="Image", description="The processed image in base64 format")
|
||||
|
||||
|
||||
class ReqFace(BaseModel):
|
||||
image: str = Field(title="Image", description="The base64 encoded image")
|
||||
model: str | None = Field(title="Model", description="The model to use for detection")
|
||||
@@ -38,8 +42,6 @@ class ResFace(BaseModel):
|
||||
images: list[str] = Field(title="Image", description="The base64 encoded images of detected faces")
|
||||
scores: list[float] = Field(title="Scores", description="The scores of the detected faces")
|
||||
|
||||
class ResMask(BaseModel):
|
||||
mask: str = Field(default='', title="Image", description="The processed image in base64 format")
|
||||
|
||||
class ItemPreprocess(BaseModel):
|
||||
name: str = Field(title="Name", description="Preprocessor name")
|
||||
@@ -215,51 +217,37 @@ class APIProcess:
|
||||
seed = req.seed or -1
|
||||
seed = processing_helpers.get_fixed_seed(seed)
|
||||
prompt = ''
|
||||
if req.type in ('text', 'image'):
|
||||
from modules.scripts_manager import scripts_txt2img
|
||||
default_model = 'google/gemma-3-4b-it' if req.type == 'image' else 'google/gemma-3-1b-it'
|
||||
model = default_model if req.model is None or len(req.model) < 4 else req.model
|
||||
instance = [s for s in scripts_txt2img.scripts if 'prompt_enhance.py' in s.filename][0]
|
||||
prompt = instance.enhance(
|
||||
model=model,
|
||||
prompt=req.prompt,
|
||||
system=req.system_prompt,
|
||||
prefix=req.prefix,
|
||||
suffix=req.suffix,
|
||||
sample=req.do_sample,
|
||||
min_tokens=req.min_tokens,
|
||||
max_tokens=req.max_tokens,
|
||||
temperature=req.temperature,
|
||||
penalty=req.repetition_penalty,
|
||||
top_k=req.top_k,
|
||||
top_p=req.top_p,
|
||||
thinking=req.thinking,
|
||||
keep_thinking=req.keep_thinking,
|
||||
use_vision=req.use_vision,
|
||||
prefill=req.prefill or '',
|
||||
keep_prefill=req.keep_prefill,
|
||||
image=decode_base64_to_image(req.image) if req.image else None,
|
||||
seed=seed,
|
||||
nsfw=req.nsfw,
|
||||
custom_args=req.custom_args,
|
||||
process_words=req.process_words,
|
||||
semantic_threshold=req.semantic_threshold,
|
||||
embedding_similarity=req.embedding_similarity,
|
||||
use_openai=req.use_openai
|
||||
)
|
||||
elif req.type == 'video':
|
||||
from modules.ui_video_vlm import enhance_prompt
|
||||
model = 'Google Gemma 3 4B' if req.model is None or len(req.model) < 4 else req.model
|
||||
prompt = enhance_prompt(
|
||||
enable=True,
|
||||
image=decode_base64_to_image(req.image),
|
||||
prompt=req.prompt,
|
||||
model=model,
|
||||
system_prompt=req.system_prompt,
|
||||
nsfw=req.nsfw,
|
||||
)
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="prompt enhancement: invalid type")
|
||||
from modules.scripts_manager import scripts_txt2img
|
||||
default_model = 'google/gemma-3-4b-it' if req.type == 'image' else 'google/gemma-3-1b-it'
|
||||
model = default_model if req.model is None or len(req.model) < 4 else req.model
|
||||
instance = [s for s in scripts_txt2img.scripts if 'prompt_enhance.py' in s.filename][0]
|
||||
prompt = instance.enhance(
|
||||
model=model,
|
||||
prompt=req.prompt,
|
||||
system=req.system_prompt,
|
||||
prefix=req.prefix,
|
||||
suffix=req.suffix,
|
||||
sample=req.do_sample,
|
||||
min_tokens=req.min_tokens,
|
||||
max_tokens=req.max_tokens,
|
||||
temperature=req.temperature,
|
||||
penalty=req.repetition_penalty,
|
||||
top_k=req.top_k,
|
||||
top_p=req.top_p,
|
||||
thinking=req.thinking,
|
||||
keep_thinking=req.keep_thinking,
|
||||
use_vision=req.use_vision,
|
||||
prefill=req.prefill or '',
|
||||
keep_prefill=req.keep_prefill,
|
||||
image=decode_base64_to_image(req.image) if req.image else None,
|
||||
seed=seed,
|
||||
nsfw=req.nsfw,
|
||||
custom_args=req.custom_args,
|
||||
process_words=req.process_words,
|
||||
semantic_threshold=req.semantic_threshold,
|
||||
embedding_similarity=req.embedding_similarity,
|
||||
use_openai=req.use_openai
|
||||
)
|
||||
res = models.ResPromptEnhance(prompt=prompt, seed=seed)
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user