Improve update script

This commit is contained in:
hlohaus 2025-06-19 15:24:49 +02:00
parent 1c88f71f05
commit 295103f224
4 changed files with 12 additions and 13 deletions

View file

@ -82,14 +82,14 @@ class Cloudflare(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
cls._args = await get_args_from_nodriver(cls.url) cls._args = await get_args_from_nodriver(cls.url)
read_models() read_models()
except Exception as e: except Exception as e:
debug.log(f"Nodriver is not available: {type(e).__name__}: {e}") debug.error(f"Nodriver is not available:", e)
cls.models = cls.fallback_models cls.models = cls.fallback_models
get_running_loop(check_nested=True) get_running_loop(check_nested=True)
try: try:
task = asyncio.create_task(nodriver_read_models()) task = asyncio.create_task(nodriver_read_models())
asyncio.run(task) asyncio.run(task)
except RuntimeError as e: except RuntimeError as e:
debug.log("Nodriver is not available:", e) debug.error("Nodriver is not available:", e)
cls.models = cls.fallback_models cls.models = cls.fallback_models
task.cancel() task.cancel()
else: else:

View file

@ -22,7 +22,7 @@ class LambdaChat(AsyncGeneratorProvider, ProviderModelMixin):
working = True working = True
default_model = "deepseek-v3-0324" default_model = "deepseek-v3"
models = [ models = [
"deepseek-llama3.3-70b", "deepseek-llama3.3-70b",
"deepseek-r1", "deepseek-r1",

View file

@ -32,7 +32,7 @@ class RequestConfig:
@classmethod @classmethod
async def get_response(cls, prompt: str) -> VideoResponse | None: async def get_response(cls, prompt: str) -> VideoResponse | None:
if prompt in cls.urls and cls.urls[prompt]: if prompt in cls.urls and cls.urls[prompt]:
unique_list = list(set(cls.urls[prompt])) unique_list = list(set(cls.urls[prompt]))[:10]
return VideoResponse(unique_list, prompt, { return VideoResponse(unique_list, prompt, {
"headers": {"authorization": cls.headers.get("authorization")} if cls.headers.get("authorization") else {}, "headers": {"authorization": cls.headers.get("authorization")} if cls.headers.get("authorization") else {},
"preview": [url.replace("md.mp4", "thumb.webp") for url in unique_list] "preview": [url.replace("md.mp4", "thumb.webp") for url in unique_list]

View file

@ -10,12 +10,11 @@ from typing import Optional
try: try:
from PIL import Image, ImageOps from PIL import Image, ImageOps
from PIL import open as open_image
has_requirements = True has_requirements = True
except ImportError: except ImportError:
has_requirements = False has_requirements = False
from ..typing import ImageType, Image from ..typing import ImageType
from ..errors import MissingRequirementsError from ..errors import MissingRequirementsError
EXTENSIONS_MAP: dict[str, str] = { EXTENSIONS_MAP: dict[str, str] = {
@ -41,7 +40,7 @@ EXTENSIONS_MAP: dict[str, str] = {
MEDIA_TYPE_MAP: dict[str, str] = {value: key for key, value in EXTENSIONS_MAP.items()} MEDIA_TYPE_MAP: dict[str, str] = {value: key for key, value in EXTENSIONS_MAP.items()}
MEDIA_TYPE_MAP["audio/webm"] = "webm" MEDIA_TYPE_MAP["audio/webm"] = "webm"
def to_image(image: ImageType, is_svg: bool = False) -> Image: def to_image(image: ImageType, is_svg: bool = False) -> Image.Image:
""" """
Converts the input image to a PIL Image object. Converts the input image to a PIL Image object.
@ -67,13 +66,13 @@ def to_image(image: ImageType, is_svg: bool = False) -> Image:
image = image.read() image = image.read()
buffer = BytesIO() buffer = BytesIO()
cairosvg.svg2png(image, write_to=buffer) cairosvg.svg2png(image, write_to=buffer)
return open_image(buffer) return Image.open(buffer)
if isinstance(image, bytes): if isinstance(image, bytes):
is_accepted_format(image) is_accepted_format(image)
return open_image(BytesIO(image)) return Image.open(BytesIO(image))
elif not isinstance(image, Image): elif not isinstance(image, Image.Image):
image = open_image(image) image = Image.open(image)
image.load() image.load()
return image return image
@ -203,7 +202,7 @@ def extract_data_uri(data_uri: str) -> bytes:
data = base64.b64decode(data) data = base64.b64decode(data)
return data return data
def process_image(image: Image, new_width: int = 800, new_height: int = 400, save: str = None) -> Image: def process_image(image: Image.Image, new_width: int = 800, new_height: int = 400, save: str = None) -> Image.Image:
""" """
Processes the given image by adjusting its orientation and resizing it. Processes the given image by adjusting its orientation and resizing it.
@ -220,7 +219,7 @@ def process_image(image: Image, new_width: int = 800, new_height: int = 400, sav
# Remove transparency # Remove transparency
if image.mode == "RGBA": if image.mode == "RGBA":
image.load() image.load()
white = open_image('RGB', image.size, (255, 255, 255)) white = Image.open('RGB', image.size, (255, 255, 255))
white.paste(image, mask=image.split()[-1]) white.paste(image, mask=image.split()[-1])
return white return white
# Convert to RGB for jpg format # Convert to RGB for jpg format