mirror of
https://github.com/ParisNeo/lollms.git
synced 2024-12-20 05:08:00 +00:00
enhanced diffusers
This commit is contained in:
parent
dad67273b5
commit
7468f4414c
@ -1,5 +1,5 @@
|
|||||||
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
|
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
|
||||||
version: 102
|
version: 104
|
||||||
binding_name: null
|
binding_name: null
|
||||||
model_name: null
|
model_name: null
|
||||||
model_variant: null
|
model_variant: null
|
||||||
@ -151,6 +151,10 @@ openai_tts_voice: "alloy"
|
|||||||
enable_sd_service: false
|
enable_sd_service: false
|
||||||
sd_base_url: http://localhost:7860
|
sd_base_url: http://localhost:7860
|
||||||
|
|
||||||
|
# diffuser
|
||||||
|
diffusers_offloading_mode: sequential_cpu_offload # sequential_cpu_offload
|
||||||
|
diffusers_model: PixArt-alpha/PixArt-Sigma-XL-2-1024-MS
|
||||||
|
|
||||||
# Dall e service key
|
# Dall e service key
|
||||||
dall_e_key: ""
|
dall_e_key: ""
|
||||||
dall_e_generation_engine: "dall-e-3"
|
dall_e_generation_engine: "dall-e-3"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
|
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
|
||||||
version: 102
|
version: 104
|
||||||
binding_name: null
|
binding_name: null
|
||||||
model_name: null
|
model_name: null
|
||||||
model_variant: null
|
model_variant: null
|
||||||
@ -151,6 +151,10 @@ openai_tts_voice: "alloy"
|
|||||||
enable_sd_service: false
|
enable_sd_service: false
|
||||||
sd_base_url: http://localhost:7860
|
sd_base_url: http://localhost:7860
|
||||||
|
|
||||||
|
# diffuser
|
||||||
|
diffusers_offloading_mode: sequential_cpu_offload # sequential_cpu_offload
|
||||||
|
diffusers_model: PixArt-alpha/PixArt-Sigma-XL-2-1024-MS
|
||||||
|
|
||||||
# Dall e service key
|
# Dall e service key
|
||||||
dall_e_key: ""
|
dall_e_key: ""
|
||||||
dall_e_generation_engine: "dall-e-3"
|
dall_e_generation_engine: "dall-e-3"
|
||||||
|
38
lollms/functions/roll_a_dice.py
Normal file
38
lollms/functions/roll_a_dice.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Lollms function call definition file
|
||||||
|
# Here you need to import any necessary imports depending on the function requested by the user
|
||||||
|
import random
|
||||||
|
|
||||||
|
# Partial is useful if we need to preset some parameters
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
# It is advised to import typing elements
|
||||||
|
# from typing import List
|
||||||
|
|
||||||
|
# Import PackageManager if there are potential libraries that need to be installed
|
||||||
|
from lollms.utilities import PackageManager
|
||||||
|
|
||||||
|
# ascii_colors offers advanced console coloring and bug tracing
|
||||||
|
from ascii_colors import trace_exception
|
||||||
|
|
||||||
|
# here is the core of the function to be built
|
||||||
|
def roll_a_dice() -> int:
|
||||||
|
try:
|
||||||
|
# handle exceptions
|
||||||
|
|
||||||
|
# Perform dice roll
|
||||||
|
result = random.randint(1, 6)
|
||||||
|
|
||||||
|
# Return the dice roll result
|
||||||
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
return trace_exception(e)
|
||||||
|
|
||||||
|
|
||||||
|
#Here is the metadata function that should have the name in format function_name_function
|
||||||
|
def roll_a_dice_function():
|
||||||
|
return {
|
||||||
|
"function_name": "roll_a_dice", # The function name in string
|
||||||
|
"function": roll_a_dice, # The function to be called
|
||||||
|
"function_description": "Returns a random dice roll result between 1 and 6.", # Description of the function
|
||||||
|
"function_parameters": [] # No parameters needed for this function
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
|
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
|
||||||
version: 102
|
version: 104
|
||||||
binding_name: null
|
binding_name: null
|
||||||
model_name: null
|
model_name: null
|
||||||
model_variant: null
|
model_variant: null
|
||||||
@ -151,6 +151,10 @@ openai_tts_voice: "alloy"
|
|||||||
enable_sd_service: false
|
enable_sd_service: false
|
||||||
sd_base_url: http://localhost:7860
|
sd_base_url: http://localhost:7860
|
||||||
|
|
||||||
|
# diffuser
|
||||||
|
diffusers_offloading_mode: sequential_cpu_offload # sequential_cpu_offload
|
||||||
|
diffusers_model: PixArt-alpha/PixArt-Sigma-XL-2-1024-MS
|
||||||
|
|
||||||
# Dall e service key
|
# Dall e service key
|
||||||
dall_e_key: ""
|
dall_e_key: ""
|
||||||
dall_e_generation_engine: "dall-e-3"
|
dall_e_generation_engine: "dall-e-3"
|
||||||
|
@ -8,7 +8,7 @@ import sys
|
|||||||
from lollms.app import LollmsApplication
|
from lollms.app import LollmsApplication
|
||||||
from lollms.paths import LollmsPaths
|
from lollms.paths import LollmsPaths
|
||||||
from lollms.config import TypedConfig, ConfigTemplate, BaseConfig
|
from lollms.config import TypedConfig, ConfigTemplate, BaseConfig
|
||||||
from lollms.utilities import PackageManager, check_and_install_torch
|
from lollms.utilities import PackageManager, check_and_install_torch, find_next_available_filename
|
||||||
import time
|
import time
|
||||||
import io
|
import io
|
||||||
import sys
|
import sys
|
||||||
@ -73,14 +73,17 @@ def install_diffusers(lollms_app:LollmsApplication):
|
|||||||
root_dir = lollms_app.lollms_paths.personal_path
|
root_dir = lollms_app.lollms_paths.personal_path
|
||||||
shared_folder = root_dir/"shared"
|
shared_folder = root_dir/"shared"
|
||||||
diffusers_folder = shared_folder / "diffusers"
|
diffusers_folder = shared_folder / "diffusers"
|
||||||
|
diffusers_folder.mkdir(exist_ok=True, parents=True)
|
||||||
if not PackageManager.check_package_installed("diffusers"):
|
if not PackageManager.check_package_installed("diffusers"):
|
||||||
PackageManager.install_or_update("diffusers")
|
PackageManager.install_or_update("diffusers")
|
||||||
diffusers_folder.mkdir(exist_ok=True, parents=True)
|
PackageManager.install_or_update("xformers")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade_diffusers(lollms_app:LollmsApplication):
|
def upgrade_diffusers(lollms_app:LollmsApplication):
|
||||||
PackageManager.install_or_update("diffusers")
|
PackageManager.install_or_update("diffusers")
|
||||||
|
PackageManager.install_or_update("xformers")
|
||||||
|
|
||||||
|
|
||||||
class LollmsDiffusers(LollmsTTI):
|
class LollmsDiffusers(LollmsTTI):
|
||||||
@ -118,10 +121,14 @@ class LollmsDiffusers(LollmsTTI):
|
|||||||
import torch
|
import torch
|
||||||
from diffusers import PixArtSigmaPipeline
|
from diffusers import PixArtSigmaPipeline
|
||||||
self.model = PixArtSigmaPipeline.from_pretrained(
|
self.model = PixArtSigmaPipeline.from_pretrained(
|
||||||
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS", torch_dtype=torch.float16, cache_dir=self.models_dir
|
app.config.diffusers_model, torch_dtype=torch.float16, cache_dir=self.models_dir,
|
||||||
|
use_safetensors=True,
|
||||||
)
|
)
|
||||||
# Enable memory optimizations.
|
# Enable memory optimizations.
|
||||||
self.model.enable_model_cpu_offload()
|
if app.config.diffusers_offloading_mode=="sequential_cpu_offload":
|
||||||
|
self.model.enable_sequential_cpu_offload()
|
||||||
|
elif app.coinfig.diffusers_offloading_mode=="model_cpu_offload":
|
||||||
|
self.model.enable_model_cpu_offload()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def verify(app:LollmsApplication):
|
def verify(app:LollmsApplication):
|
||||||
@ -162,11 +169,13 @@ class LollmsDiffusers(LollmsTTI):
|
|||||||
restore_faces=True,
|
restore_faces=True,
|
||||||
output_path=None
|
output_path=None
|
||||||
):
|
):
|
||||||
|
if output_path is None:
|
||||||
array = self.model(diffusers_positive_prompt).images[0]
|
output_path = self.output_dir
|
||||||
image = Image.fromarray(array)
|
from diffusers.utils.pil_utils import pt_to_pil
|
||||||
|
image = self.model(diffusers_positive_prompt, negative_prompt=diffusers_negative_prompt, guidance_scale=scale, num_inference_steps=steps,).images[0]
|
||||||
|
output_path = Path(output_path)
|
||||||
|
fn = find_next_available_filename(output_path,"diff_img_")
|
||||||
# Save the image
|
# Save the image
|
||||||
image.save('output_image.png')
|
image.save(fn)
|
||||||
return None, None
|
return fn, {"prompt":diffusers_positive_prompt, "negative_prompt":diffusers_negative_prompt}
|
||||||
|
|
||||||
|
@ -199,7 +199,10 @@ class LollmsXTTS(LollmsTTS):
|
|||||||
"top_k": self.app.config.xtts_top_k,
|
"top_k": self.app.config.xtts_top_k,
|
||||||
"enable_text_splitting": self.app.config.xtts_enable_text_splitting
|
"enable_text_splitting": self.app.config.xtts_enable_text_splitting
|
||||||
}
|
}
|
||||||
response = requests.post(f"{self.xtts_base_url}/set_tts_settings", settings)
|
response = requests.post(f"{self.xtts_base_url}/set_tts_settings", settings,headers={
|
||||||
|
'accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
})
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
ASCIIColors.success("XTTS updated successfully")
|
ASCIIColors.success("XTTS updated successfully")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
Loading…
Reference in New Issue
Block a user