mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-02-03 09:40:40 +00:00
Upgraded core
This commit is contained in:
parent
01ec6b724b
commit
ad328a8c79
@ -4,6 +4,7 @@ from lollms.personality import PersonalityBuilder
|
||||
from lollms.binding import LLMBinding, BindingBuilder, ModelBuilder
|
||||
from lollms.extension import LOLLMSExtension, ExtensionBuilder
|
||||
from lollms.config import InstallOption
|
||||
from lollms.helpers import NotificationType
|
||||
from lollms.helpers import trace_exception
|
||||
from lollms.terminal import MainMenu
|
||||
from lollms.utilities import PromptReshaper
|
||||
@ -17,6 +18,7 @@ import subprocess
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
|
||||
class LollmsApplication:
|
||||
def __init__(
|
||||
self,
|
||||
@ -226,14 +228,20 @@ class LollmsApplication:
|
||||
generated_text = self.personality.model.generate(full_discussion, n_predict=n_predict, callback=callback)
|
||||
return generated_text
|
||||
|
||||
def notify(self, content, is_success=True, duration=4, client_id=None, notification_type=0):
|
||||
if self.notification_callback:
|
||||
return self.notification_callback(content, is_success, duration, client_id, notification_type)
|
||||
def notify(self, content, notification_type:NotificationType=NotificationType.NOTIF_SUCCESS, duration=4, client_id=None, verbose= True):
|
||||
if verbose:
|
||||
if notification_type==NotificationType.NOTIF_SUCCESS:
|
||||
ASCIIColors.success(content)
|
||||
elif notification_type==NotificationType.NOTIF_INFO:
|
||||
ASCIIColors.info(content)
|
||||
elif notification_type==NotificationType.NOTIF_WARNING:
|
||||
ASCIIColors.warning(content)
|
||||
else:
|
||||
ASCIIColors.red(content)
|
||||
|
||||
if self.notification_callback:
|
||||
return self.notification_callback(content, notification_type, duration, client_id)
|
||||
|
||||
if is_success:
|
||||
ASCIIColors.yellow(content)
|
||||
else:
|
||||
ASCIIColors.red(content)
|
||||
|
||||
def load_binding(self):
|
||||
try:
|
||||
|
@ -21,6 +21,7 @@ import importlib
|
||||
import subprocess
|
||||
from lollms.config import TypedConfig, InstallOption
|
||||
from lollms.main_config import LOLLMSConfig
|
||||
from lollms.helpers import NotificationType
|
||||
import urllib
|
||||
import inspect
|
||||
from enum import Enum
|
||||
@ -103,9 +104,19 @@ class LLMBinding:
|
||||
for models_folder in self.models_folders:
|
||||
models_folder.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def notify(self, content:str, status:bool=True, duration=4, notification_type=0):
|
||||
def notify(self, content:str, notification_type:NotificationType=NotificationType.NOTIF_SUCCESS, duration=4, verbose=True):
|
||||
if verbose:
|
||||
if notification_type==NotificationType.NOTIF_SUCCESS:
|
||||
ASCIIColors.success(content)
|
||||
elif notification_type==NotificationType.NOTIF_INFO:
|
||||
ASCIIColors.info(content)
|
||||
elif notification_type==NotificationType.NOTIF_WARNING:
|
||||
ASCIIColors.warning(content)
|
||||
else:
|
||||
ASCIIColors.red(content)
|
||||
|
||||
if self.notification_callback:
|
||||
self.notification_callback(content, status)
|
||||
self.notification_callback(content, notification_type, duration)
|
||||
|
||||
|
||||
def settings_updated(self):
|
||||
|
@ -1,6 +1,29 @@
|
||||
import traceback
|
||||
from ascii_colors import ASCIIColors
|
||||
from enum import Enum
|
||||
class NotificationType(Enum):
|
||||
"""Notification types."""
|
||||
|
||||
NOTIF_ERROR = 0
|
||||
"""This is an error notification."""
|
||||
|
||||
NOTIF_SUCCESS = 1
|
||||
"""This is a success notification."""
|
||||
|
||||
NOTIF_INFO = 2
|
||||
"""This is an information notification."""
|
||||
|
||||
NOTIF_WARNING = 3
|
||||
"""This is a warining notification."""
|
||||
|
||||
class NotificationDisplayType(Enum):
|
||||
"""Notification display types."""
|
||||
|
||||
TOAST = 0
|
||||
"""This is a toast."""
|
||||
|
||||
MESSAGE_BOX = 1
|
||||
"""This is a message box."""
|
||||
|
||||
def get_trace_exception(ex):
|
||||
"""
|
||||
|
@ -23,6 +23,70 @@ import json
|
||||
import base64
|
||||
|
||||
|
||||
|
||||
class AudioRecorder:
|
||||
def __init__(self, filename, channels=1, sample_rate=44100, chunk_size=1024, silence_threshold=0.01, silence_duration=2):
|
||||
self.filename = filename
|
||||
self.channels = channels
|
||||
self.sample_rate = sample_rate
|
||||
self.chunk_size = chunk_size
|
||||
self.audio_format = pyaudio.paInt16
|
||||
self.audio_stream = None
|
||||
self.audio_frames = []
|
||||
self.is_recording = False
|
||||
self.silence_threshold = silence_threshold
|
||||
self.silence_duration = silence_duration
|
||||
self.last_sound_time = time.time()
|
||||
|
||||
def start_recording(self):
|
||||
self.is_recording = True
|
||||
self.audio_stream = pyaudio.PyAudio().open(
|
||||
format=self.audio_format,
|
||||
channels=self.channels,
|
||||
rate=self.sample_rate,
|
||||
input=True,
|
||||
frames_per_buffer=self.chunk_size
|
||||
)
|
||||
|
||||
print("Recording started...")
|
||||
|
||||
threading.Thread(target=self._record).start()
|
||||
|
||||
def _record(self):
|
||||
while self.is_recording:
|
||||
data = self.audio_stream.read(self.chunk_size)
|
||||
self.audio_frames.append(data)
|
||||
|
||||
# Check for silence
|
||||
rms = self._calculate_rms(data)
|
||||
if rms < self.silence_threshold:
|
||||
current_time = time.time()
|
||||
if current_time - self.last_sound_time >= self.silence_duration:
|
||||
self.stop_recording()
|
||||
else:
|
||||
self.last_sound_time = time.time()
|
||||
|
||||
def _calculate_rms(self, data):
|
||||
squared_sum = sum([sample ** 2 for sample in data])
|
||||
rms = (squared_sum / len(data)) ** 0.5
|
||||
return rms
|
||||
|
||||
def stop_recording(self):
|
||||
self.is_recording = False
|
||||
self.audio_stream.stop_stream()
|
||||
self.audio_stream.close()
|
||||
|
||||
audio = wave.open(self.filename, 'wb')
|
||||
audio.setnchannels(self.channels)
|
||||
audio.setsampwidth(pyaudio.PyAudio().get_sample_size(self.audio_format))
|
||||
audio.setframerate(self.sample_rate)
|
||||
audio.writeframes(b''.join(self.audio_frames))
|
||||
audio.close()
|
||||
|
||||
print(f"Recording saved to {self.filename}")
|
||||
|
||||
|
||||
|
||||
class WebcamImageSender:
|
||||
"""
|
||||
Class for capturing images from the webcam and sending them to a SocketIO client.
|
||||
|
Loading…
x
Reference in New Issue
Block a user