Extensions performance & memory optimisations
Reworked remove_surrounded_chars() to use regular expression ( https://regexr.com/7alb5 ) instead of repeated string concatenations for elevenlab_tts, silero_tts, sd_api_pictures. This should be both faster and more robust in handling asterisks. Reduced the memory footprint of send_pictures and sd_api_pictures by scaling the images in the chat to 300 pixels max-side wise. (The user already has the original in case of the sent picture and there's an option to save the SD generation). This should fix history growing annoyingly large with multiple pictures present
This commit is contained in:
parent
45b7e53565
commit
5389fce8e1
4 changed files with 39 additions and 27 deletions
|
@ -4,6 +4,8 @@ import gradio as gr
|
|||
from elevenlabslib import ElevenLabsUser
|
||||
from elevenlabslib.helpers import save_bytes_to_path
|
||||
|
||||
import re
|
||||
|
||||
import modules.shared as shared
|
||||
|
||||
params = {
|
||||
|
@ -52,14 +54,10 @@ def refresh_voices():
|
|||
return
|
||||
|
||||
def remove_surrounded_chars(string):
|
||||
new_string = ""
|
||||
in_star = False
|
||||
for char in string:
|
||||
if char == '*':
|
||||
in_star = not in_star
|
||||
elif not in_star:
|
||||
new_string += char
|
||||
return new_string
|
||||
# regexp is way faster than repeated string concatenation!
|
||||
# this expression matches to 'as few symbols as possible (0 upwards) between any asterisks' OR
|
||||
# 'as few symbols as possible (0 upwards) between an asterisk and the end of the string'
|
||||
return re.sub('\*[^\*]*?(\*|$)','',string)
|
||||
|
||||
def input_modifier(string):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue