fixed pyqt5 and other tools

This commit is contained in:
Saifeddine ALOUI 2024-10-08 21:37:39 +02:00
parent b304981082
commit 246f2e3df8
9 changed files with 136 additions and 177 deletions

View File

@ -1,10 +1,6 @@
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.utilities import discussion_path_to_url
from lollms.client_session import Client
from lollms.personality import APScript
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
from ascii_colors import trace_exception
from functools import partial
from lollms.functions.prompting.image_gen_prompts import get_image_gen_prompt, get_random_image_gen_prompt

View File

@ -1,15 +1,7 @@
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.utilities import find_first_available_file_index, discussion_path_to_url
from lollms.client_session import Client
from lollms.personality import APScript
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
from ascii_colors import trace_exception
import cv2
import time
from PyQt5 import QtWidgets, QtGui, QtCore
import sys
from functools import partial
from lollms.personality import AIPersonality
from typing import List

View File

@ -207,10 +207,6 @@ def two_paths_meme_generator_function(client: Client) -> Dict:
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.client_session import Client
from lollms.personality import APScript
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
from ascii_colors import trace_exception
from functools import partial
from PIL import Image, ImageDraw, ImageFont

View File

@ -1,20 +1,20 @@
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.client_session import Client
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
if not PackageManager.check_package_installed("cv2"):
PackageManager.install_package("opencv-python")
import cv2
import time
from PyQt5 import QtWidgets, QtGui, QtCore
import sys
from functools import partial
import pipmaster as pm
def select_image_file(processor, client):
if not pm.is_installed("PyQt5"):
pm.install("PyQt5")
if not pm.is_installed("cv2"):
pm.install("opencv-python")
import cv2
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.ReadOnly

View File

@ -1,15 +1,7 @@
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.client_session import Client
from lollms.personality import APScript
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
from ascii_colors import trace_exception
import cv2
import time
from PyQt5 import QtWidgets, QtGui, QtCore
import sys
from functools import partial
from lollms.personality import AIPersonality
from typing import List

View File

@ -1,78 +1,79 @@
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.utilities import find_first_available_file_index, discussion_path_to_url
from lollms.client_session import Client
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
import cv2
import time
from PyQt5 import QtWidgets, QtGui, QtCore
import sys
from functools import partial
class CameraWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.cap = cv2.VideoCapture(0)
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.update_frame)
self.timer.start(50)
def initUI(self):
self.setWindowTitle('Camera')
self.image_label = QtWidgets.QLabel(self)
self.image_label.resize(640, 480)
self.captured_image_label = QtWidgets.QLabel(self)
self.captured_image_label.resize(640, 480)
self.take_shot_button = QtWidgets.QPushButton('Take Shot', self)
self.take_shot_button.clicked.connect(self.take_shot)
self.ok_button = QtWidgets.QPushButton('OK', self)
self.ok_button.clicked.connect(self.ok)
self.hbox_layout = QtWidgets.QHBoxLayout()
self.hbox_layout.addWidget(self.image_label)
self.hbox_layout.addWidget(self.captured_image_label)
self.vbox_layout = QtWidgets.QVBoxLayout()
self.vbox_layout.addLayout(self.hbox_layout)
self.vbox_layout.addWidget(self.take_shot_button)
self.vbox_layout.addWidget(self.ok_button)
self.setLayout(self.vbox_layout)
def update_frame(self):
ret, frame = self.cap.read()
if ret:
self.frame = frame
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
height, width, channel = image.shape
step = channel * width
qImg = QtGui.QImage(image.data, width, height, step, QtGui.QImage.Format_RGB888)
self.image_label.setPixmap(QtGui.QPixmap.fromImage(qImg))
def take_shot(self):
if hasattr(self, 'frame'):
self.captured_frame = self.frame
image = cv2.cvtColor(self.captured_frame, cv2.COLOR_BGR2RGB)
height, width, channel = image.shape
step = channel * width
qImg = QtGui.QImage(image.data, width, height, step, QtGui.QImage.Format_RGB888)
self.captured_image_label.setPixmap(QtGui.QPixmap.fromImage(qImg))
def ok(self):
if hasattr(self, 'captured_frame'):
self.close()
def closeEvent(self, event):
self.cap.release()
event.accept()
import pipmaster as pm
def take_photo(processor, client, use_ui=False, use_a_single_photo_at_a_time=True):
if not pm.is_installed("PyQt5"):
pm.install("PyQt5")
if not pm.is_installed("cv2"):
pm.install("opencv-python")
import cv2
import time
from PyQt5 import QtWidgets, QtGui, QtCore
class CameraWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.cap = cv2.VideoCapture(0)
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.update_frame)
self.timer.start(50)
def initUI(self):
self.setWindowTitle('Camera')
self.image_label = QtWidgets.QLabel(self)
self.image_label.resize(640, 480)
self.captured_image_label = QtWidgets.QLabel(self)
self.captured_image_label.resize(640, 480)
self.take_shot_button = QtWidgets.QPushButton('Take Shot', self)
self.take_shot_button.clicked.connect(self.take_shot)
self.ok_button = QtWidgets.QPushButton('OK', self)
self.ok_button.clicked.connect(self.ok)
self.hbox_layout = QtWidgets.QHBoxLayout()
self.hbox_layout.addWidget(self.image_label)
self.hbox_layout.addWidget(self.captured_image_label)
self.vbox_layout = QtWidgets.QVBoxLayout()
self.vbox_layout.addLayout(self.hbox_layout)
self.vbox_layout.addWidget(self.take_shot_button)
self.vbox_layout.addWidget(self.ok_button)
self.setLayout(self.vbox_layout)
def update_frame(self):
ret, frame = self.cap.read()
if ret:
self.frame = frame
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
height, width, channel = image.shape
step = channel * width
qImg = QtGui.QImage(image.data, width, height, step, QtGui.QImage.Format_RGB888)
self.image_label.setPixmap(QtGui.QPixmap.fromImage(qImg))
def take_shot(self):
if hasattr(self, 'frame'):
self.captured_frame = self.frame
image = cv2.cvtColor(self.captured_frame, cv2.COLOR_BGR2RGB)
height, width, channel = image.shape
step = channel * width
qImg = QtGui.QImage(image.data, width, height, step, QtGui.QImage.Format_RGB888)
self.captured_image_label.setPixmap(QtGui.QPixmap.fromImage(qImg))
def ok(self):
if hasattr(self, 'captured_frame'):
self.close()
def closeEvent(self, event):
self.cap.release()
event.accept()
if use_ui:
def run_app():
app = QtWidgets.QApplication(sys.argv)

View File

@ -1,55 +1,56 @@
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.utilities import find_first_available_file_index, discussion_path_to_url
from lollms.client_session import Client
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
import pipmaster as pm
import pyautogui
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import Qt
import sys
from functools import partial
class ScreenshotWindow(QtWidgets.QWidget):
def __init__(self, client, screenshot, fn_view, fn, use_a_single_photo_at_a_time= True):
super().__init__()
self.client = client
self.screenshot = screenshot
self.fn_view = fn_view
self.fn = fn
self.use_a_single_photo_at_a_time = use_a_single_photo_at_a_time
self.initUI()
def initUI(self):
self.setWindowTitle('Screenshot Viewer')
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel(self)
self.pixmap = QtGui.QPixmap(self.screenshot)
self.label.setPixmap(self.pixmap)
self.layout.addWidget(self.label)
self.ok_button = QtWidgets.QPushButton('OK')
self.ok_button.clicked.connect(self.save_and_close)
self.layout.addWidget(self.ok_button)
self.setLayout(self.layout)
def save_and_close(self):
self.screenshot.save(self.fn_view)
self.screenshot.save(self.fn)
self.client.discussion.image_files.append(self.fn)
if self.use_a_single_photo_at_a_time:
self.client.discussion.image_files = [self.client.discussion.image_files[-1]]
self.close()
def take_screenshot(client: Client, use_ui: bool = False, use_a_single_photo_at_a_time= True):
if not pm.is_installed("pyautogui"):
pm.install("pyautogui")
if not pm.is_installed("PyQt5"):
pm.install("PyQt5")
import pyautogui
from PyQt5 import QtWidgets, QtGui
import sys
class ScreenshotWindow(QtWidgets.QWidget):
def __init__(self, client, screenshot, fn_view, fn, use_a_single_photo_at_a_time= True):
super().__init__()
self.client = client
self.screenshot = screenshot
self.fn_view = fn_view
self.fn = fn
self.use_a_single_photo_at_a_time = use_a_single_photo_at_a_time
self.initUI()
def initUI(self):
self.setWindowTitle('Screenshot Viewer')
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel(self)
self.pixmap = QtGui.QPixmap(self.screenshot)
self.label.setPixmap(self.pixmap)
self.layout.addWidget(self.label)
self.ok_button = QtWidgets.QPushButton('OK')
self.ok_button.clicked.connect(self.save_and_close)
self.layout.addWidget(self.ok_button)
self.setLayout(self.layout)
def save_and_close(self):
self.screenshot.save(self.fn_view)
self.screenshot.save(self.fn)
self.client.discussion.image_files.append(self.fn)
if self.use_a_single_photo_at_a_time:
self.client.discussion.image_files = [self.client.discussion.image_files[-1]]
self.close()
screenshot = pyautogui.screenshot()
view_image = client.discussion.discussion_folder / "view_images"
image = client.discussion.discussion_folder / "images"

View File

@ -19,17 +19,11 @@ from lollms.utilities import PackageManager
from ascii_colors import trace_exception
# Here is an example of how we install a non installed library using PackageManager
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
import pipmaster as pm
# now we can import the libraries
import threading
import time
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
import pyautogui
# here is the core of the function to be built
def set_timer_with_alert(duration: int, message: str) -> str:
@ -43,6 +37,10 @@ def set_timer_with_alert(duration: int, message: str) -> str:
Returns:
str: A success message indicating the timer has been set.
"""
if not pm.is_installed("pyautogui"):
pm.install("pyautogui")
import pyautogui
def timer_callback():
try:
time.sleep(duration)

View File

@ -4,28 +4,11 @@ from typing import Optional
from base64 import b64encode
import io
from PIL import Image
from fastapi import APIRouter, Request
from fastapi import APIRouter
from lollms_webui import LOLLMSWebUI
from pydantic import BaseModel
from starlette.responses import StreamingResponse
from lollms.types import MSG_OPERATION_TYPE
from lollms.utilities import detect_antiprompt, remove_text_from_string, trace_exception
from lollms.security import sanitize_path
from ascii_colors import ASCIIColors
from lollms.databases.discussions_database import DiscussionsDB, Discussion
from lollms.security import check_access
from typing import List
from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url
from lollms.client_session import Client
from lollms.personality import APScript
if not PackageManager.check_package_installed("pyautogui"):
PackageManager.install_package("pyautogui")
if not PackageManager.check_package_installed("PyQt5"):
PackageManager.install_package("PyQt5")
from ascii_colors import trace_exception
from functools import partial
from lollms.functions.prompting.image_gen_prompts import get_image_gen_prompt, get_random_image_gen_prompt
router = APIRouter()