Skip to content

Commit

Permalink
afix engine test bug caused by no-clear between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh1994 committed Nov 20, 2024
1 parent 0e89d64 commit 0735990
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 29 deletions.
5 changes: 1 addition & 4 deletions lazyllm/components/embedding/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import json
import lazyllm
from lazyllm import LOG
from lazyllm.thirdparty import transformers as tf
from lazyllm.thirdparty import torch
from lazyllm.thirdparty import sentence_transformers
import numpy as np
from lazyllm.thirdparty import transformers as tf, torch, sentence_transformers, numpy as np


class LazyHuggingFaceEmbedding(object):
Expand Down
12 changes: 6 additions & 6 deletions lazyllm/components/stable_diffusion/stable_diffusion3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import base64
import uuid
from PIL import Image
import numpy as np
from lazyllm.thirdparty import PIL
from lazyllm.thirdparty import numpy as np
from io import BytesIO

import lazyllm
Expand Down Expand Up @@ -31,12 +31,12 @@ def load_sd(self):

@staticmethod
def image_to_base64(image):
if isinstance(image, Image.Image):
if isinstance(image, PIL.Image.Image):
buffered = BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
elif isinstance(image, np.ndarray):
image = Image.fromarray(image)
image = PIL.Image.fromarray(image)
buffered = BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
Expand All @@ -50,10 +50,10 @@ def images_to_base64(images):

@staticmethod
def image_to_file(image, file_path):
if isinstance(image, Image.Image):
if isinstance(image, PIL.Image.Image):
image.save(file_path, format="PNG")
elif isinstance(image, np.ndarray):
image = Image.fromarray(image)
image = PIL.Image.fromarray(image)
image.save(file_path, format="PNG")
else:
raise ValueError("Unsupported image type")
Expand Down
2 changes: 1 addition & 1 deletion lazyllm/components/text_to_speech/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ..utils.file_operate import delete_old_files


def sound_to_file(sound: np.array, file_path: str, sample_rate: int = 24000) -> str:
def sound_to_file(sound: 'np.array', file_path: str, sample_rate: int = 24000) -> str:
scaled_audio = np.int16(sound / np.max(np.abs(sound)) * 32767)
scipy.io.wavfile.write(file_path, sample_rate, scaled_audio)
return [file_path]
Expand Down
2 changes: 1 addition & 1 deletion lazyllm/thirdparty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ def __getattribute__(self, __name):
modules = ['redis', 'huggingface_hub', 'jieba', 'modelscope', 'pandas', 'jwt', 'rank_bm25', 'redisvl', 'datasets',
'deepspeed', 'fire', 'numpy', 'peft', 'torch', 'transformers', 'collie', 'faiss', 'flash_attn', 'google',
'lightllm', 'vllm', 'ChatTTS', 'wandb', 'funasr', 'sklearn', 'torchvision', 'scipy', 'pymilvus',
'sentence_transformers', 'gradio', 'chromadb']
'sentence_transformers', 'gradio', 'chromadb', 'nltk', 'PIL', 'httpx', 'bm25s']
for m in modules:
vars()[m] = PackageWrapper(m)
3 changes: 1 addition & 2 deletions lazyllm/tools/rag/component/bm25.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import List, Tuple
from ..doc_node import DocNode
import bm25s
import Stemmer
from lazyllm.thirdparty import jieba
from lazyllm.thirdparty import jieba, bm25s
from .stopwords import STOPWORDS_CHINESE


Expand Down
12 changes: 6 additions & 6 deletions lazyllm/tools/rag/readers/imageReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
from pathlib import Path
from typing import Dict, List, Optional, cast
from fsspec import AbstractFileSystem
from PIL import Image
from lazyllm.thirdparty import PIL

from .readerBase import LazyLLMReaderBase, infer_torch_device
from ..doc_node import DocNode

def img_2_b64(image: Image, format: str = "JPEG") -> str:
def img_2_b64(image: 'PIL.Image', format: str = "JPEG") -> str:
buff = BytesIO()
image.save(buff, format=format)
return cast(str, base64.b64encode(buff.getvalue()))

def b64_2_img(data: str) -> Image:
def b64_2_img(data: str) -> 'PIL.Image':
buff = BytesIO(base64.b64decode(data))
return Image.open(buff)
return 'PIL.Image'.open(buff)

class ImageReader(LazyLLMReaderBase):
def __init__(self, parser_config: Optional[Dict] = None, keep_image: bool = False, parse_text: bool = False,
Expand Down Expand Up @@ -59,9 +59,9 @@ def _load_data(self, file: Path, extra_info: Optional[Dict] = None,

if fs:
with fs.open(path=file) as f:
image = Image.open(f.read())
image = PIL.Image.open(f.read())
else:
image = Image.open(file)
image = PIL.Image.open(file)

if image.mode != "RGB": image = image.convert("RGB")

Expand Down
2 changes: 1 addition & 1 deletion lazyllm/tools/rag/readers/pandasReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, List, Optional
from fsspec import AbstractFileSystem
import importlib
import pandas as pd
from lazyllm.thirdparty import pandas as pd

from .readerBase import LazyLLMReaderBase
from ..doc_node import DocNode
Expand Down
2 changes: 1 addition & 1 deletion lazyllm/tools/rag/similarity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional, Callable, Literal, List
from .component.bm25 import BM25
import numpy as np
from lazyllm.thirdparty import numpy as np
from .doc_node import DocNode

registered_similarities = dict()
Expand Down
2 changes: 1 addition & 1 deletion lazyllm/tools/rag/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
from typing import Any, Callable, Dict, List, Tuple, Union, Optional
from lazyllm.components import AlpacaPrompter
import nltk
from lazyllm.thirdparty import nltk
import tiktoken

from .doc_node import DocNode, MetadataMode
Expand Down
5 changes: 2 additions & 3 deletions lazyllm/tools/webpages/webmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import sys
import requests
import traceback
from lazyllm.thirdparty import gradio as gr
from lazyllm.thirdparty import gradio as gr, PIL
import time
from PIL import Image
import re

import lazyllm
Expand Down Expand Up @@ -322,7 +321,7 @@ def get_log_and_message(s):
for i, file_path in enumerate(file_paths):
suffix = os.path.splitext(file_path)[-1].lower()
file = None
if suffix in Image.registered_extensions().keys():
if suffix in PIL.Image.registered_extensions().keys():
file = gr.Image(file_path)
elif suffix in ('.mp3', '.wav'):
file = gr.Audio(file_path)
Expand Down
4 changes: 2 additions & 2 deletions tests/advanced_tests/full_test/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import random
from gradio_client import Client
from PIL import Image
from lazyllm.thirdparty import PIL

import lazyllm
from lazyllm.launcher import cleanup
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_painting(self):
assert type(res) is dict
assert "files" in res
assert len(res['files']) == 1
image = Image.open(res['files'][0])
image = PIL.Image.open(res['files'][0])
assert image.size == (1024, 1024)

# test painting warpped in web
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_tests/test_bm25.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from lazyllm.tools.rag.component.bm25 import BM25
from lazyllm.tools.rag.doc_node import DocNode
import numpy as np
from lazyllm.thirdparty import numpy as np


class TestBM25(unittest.TestCase):
Expand Down

0 comments on commit 0735990

Please sign in to comment.