mirror of
https://github.com/ParisNeo/lollms.git
synced 2024-12-19 04:37:54 +00:00
Upgraded notification
This commit is contained in:
parent
d250265cb0
commit
6ae9d52d98
@ -1002,7 +1002,7 @@ class LollmsSD:
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
print("Service is available.")
|
print("Service is available.")
|
||||||
if self.app is not None:
|
if self.app is not None:
|
||||||
self.app.notify("SD Service is now available.", True)
|
self.app.success("SD Service is now available.")
|
||||||
return True
|
return True
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
pass
|
pass
|
||||||
@ -1012,7 +1012,7 @@ class LollmsSD:
|
|||||||
if show_warning:
|
if show_warning:
|
||||||
print("Service did not become available within the given time.")
|
print("Service did not become available within the given time.")
|
||||||
if self.app is not None:
|
if self.app is not None:
|
||||||
self.app.notify("SD Service did not become available within the given time.", False)
|
self.app.error("SD Service did not become available within the given time.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_available_image_name(self, save_folder, base_name):
|
def get_available_image_name(self, save_folder, base_name):
|
||||||
|
@ -7,6 +7,7 @@ Description: Media classes:
|
|||||||
License: Apache 2.0
|
License: Apache 2.0
|
||||||
"""
|
"""
|
||||||
from lollms.utilities import PackageManager
|
from lollms.utilities import PackageManager
|
||||||
|
from lollms.com import LoLLMsCom
|
||||||
if not PackageManager.check_package_installed("pygame"):
|
if not PackageManager.check_package_installed("pygame"):
|
||||||
PackageManager.install_package("pygame")
|
PackageManager.install_package("pygame")
|
||||||
import pygame
|
import pygame
|
||||||
@ -39,9 +40,9 @@ else:
|
|||||||
|
|
||||||
if not PackageManager.check_package_installed("matplotlib"):
|
if not PackageManager.check_package_installed("matplotlib"):
|
||||||
PackageManager.install_package("matplotlib")
|
PackageManager.install_package("matplotlib")
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
else:
|
import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
matplotlib.use('Agg')
|
||||||
|
|
||||||
from lollms.com import LoLLMsCom
|
from lollms.com import LoLLMsCom
|
||||||
import time
|
import time
|
||||||
@ -51,7 +52,7 @@ import io
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
class AudioRecorder:
|
class AudioRecorder:
|
||||||
def __init__(self, socketio, filename, channels=1, sample_rate=44100, chunk_size=1024, silence_threshold=0.01, silence_duration=2, app:LoLLMsCom=None):
|
def __init__(self, socketio, filename, channels=1, sample_rate=44100, chunk_size=1024, silence_threshold=0.1, silence_duration=2, lollmsCom:LoLLMsCom=None):
|
||||||
self.socketio = socketio
|
self.socketio = socketio
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.channels = channels
|
self.channels = channels
|
||||||
@ -64,7 +65,7 @@ class AudioRecorder:
|
|||||||
self.silence_threshold = silence_threshold
|
self.silence_threshold = silence_threshold
|
||||||
self.silence_duration = silence_duration
|
self.silence_duration = silence_duration
|
||||||
self.last_sound_time = time.time()
|
self.last_sound_time = time.time()
|
||||||
self.app = app
|
self.lollmsCom = lollmsCom
|
||||||
|
|
||||||
def start_recording(self):
|
def start_recording(self):
|
||||||
self.is_recording = True
|
self.is_recording = True
|
||||||
@ -76,7 +77,7 @@ class AudioRecorder:
|
|||||||
frames_per_buffer=self.chunk_size
|
frames_per_buffer=self.chunk_size
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Recording started...")
|
self.lollmsCom.info("Recording started...")
|
||||||
|
|
||||||
threading.Thread(target=self._record).start()
|
threading.Thread(target=self._record).start()
|
||||||
|
|
||||||
@ -90,7 +91,10 @@ class AudioRecorder:
|
|||||||
if rms < self.silence_threshold:
|
if rms < self.silence_threshold:
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
if current_time - self.last_sound_time >= self.silence_duration:
|
if current_time - self.last_sound_time >= self.silence_duration:
|
||||||
self.stop_recording()
|
self.lollmsCom.info("Analyzing")
|
||||||
|
self.audio_stream.stop_stream()
|
||||||
|
self.audio_stream.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.last_sound_time = time.time()
|
self.last_sound_time = time.time()
|
||||||
|
|
||||||
@ -131,14 +135,14 @@ class AudioRecorder:
|
|||||||
self.audio_stream.stop_stream()
|
self.audio_stream.stop_stream()
|
||||||
self.audio_stream.close()
|
self.audio_stream.close()
|
||||||
|
|
||||||
audio = wave.open(self.filename, 'wb')
|
audio = wave.open(str(self.filename), 'wb')
|
||||||
audio.setnchannels(self.channels)
|
audio.setnchannels(self.channels)
|
||||||
audio.setsampwidth(pyaudio.PyAudio().get_sample_size(self.audio_format))
|
audio.setsampwidth(pyaudio.PyAudio().get_sample_size(self.audio_format))
|
||||||
audio.setframerate(self.sample_rate)
|
audio.setframerate(self.sample_rate)
|
||||||
audio.writeframes(b''.join(self.audio_frames))
|
audio.writeframes(b''.join(self.audio_frames))
|
||||||
audio.close()
|
audio.close()
|
||||||
|
|
||||||
print(f"Recording saved to {self.filename}")
|
self.lollmsCom.info(f"Recording saved to {self.filename}")
|
||||||
|
|
||||||
|
|
||||||
class WebcamImageSender:
|
class WebcamImageSender:
|
||||||
@ -146,7 +150,7 @@ class WebcamImageSender:
|
|||||||
Class for capturing images from the webcam and sending them to a SocketIO client.
|
Class for capturing images from the webcam and sending them to a SocketIO client.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, socketio):
|
def __init__(self, socketio, lollmsCom:LoLLMsCom=None):
|
||||||
"""
|
"""
|
||||||
Initializes the WebcamImageSender class.
|
Initializes the WebcamImageSender class.
|
||||||
|
|
||||||
@ -158,6 +162,7 @@ class WebcamImageSender:
|
|||||||
self.last_change_time = None
|
self.last_change_time = None
|
||||||
self.capture_thread = None
|
self.capture_thread = None
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
|
self.lollmsCom = lollmsCom
|
||||||
|
|
||||||
def start_capture(self):
|
def start_capture(self):
|
||||||
"""
|
"""
|
||||||
@ -178,6 +183,7 @@ class WebcamImageSender:
|
|||||||
"""
|
"""
|
||||||
Captures images from the webcam, checks if the image content has changed, and sends the image to the client if it remains the same for 3 seconds.
|
Captures images from the webcam, checks if the image content has changed, and sends the image to the client if it remains the same for 3 seconds.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
cap = cv2.VideoCapture(0)
|
cap = cv2.VideoCapture(0)
|
||||||
|
|
||||||
while self.is_running:
|
while self.is_running:
|
||||||
@ -193,6 +199,8 @@ class WebcamImageSender:
|
|||||||
self.socketio.emit("image", image_base64.decode('utf-8'))
|
self.socketio.emit("image", image_base64.decode('utf-8'))
|
||||||
|
|
||||||
cap.release()
|
cap.release()
|
||||||
|
except:
|
||||||
|
self.lollmsCom.error("Couldn't start webcam")
|
||||||
|
|
||||||
def image_difference(self, image):
|
def image_difference(self, image):
|
||||||
"""
|
"""
|
||||||
|
@ -1565,7 +1565,7 @@ class APScript(StateMachine):
|
|||||||
self.notify = personality.app.notify
|
self.notify = personality.app.notify
|
||||||
self.text_files = []
|
self.text_files = []
|
||||||
self.image_files = []
|
self.image_files = []
|
||||||
self.images_descriptions=[]
|
self.images_descriptions = []
|
||||||
|
|
||||||
self.personality = personality
|
self.personality = personality
|
||||||
self.personality_config = personality_config
|
self.personality_config = personality_config
|
||||||
|
Loading…
Reference in New Issue
Block a user