Skip to content

Commit

Permalink
Added camera release on off
Browse files Browse the repository at this point in the history
  • Loading branch information
szczyglis-dev committed Dec 10, 2023
1 parent be3c501 commit ca72f2c
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 16 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PYGPT v2

Release: **2.0.14** build: **2023.12.10** | Official website: https://pygpt.net | Docs: https://pygpt.readthedocs.io
Release: **2.0.15** build: **2023.12.10** | Official website: https://pygpt.net | Docs: https://pygpt.readthedocs.io

PyPi: https://pypi.org/project/pygpt-net

Expand Down Expand Up @@ -1062,6 +1062,10 @@ may consume additional tokens that are not displayed in the main window.

# CHANGELOG

## 2.0.15 (2023-12-10)

- Added camera release / disable on camera off

## 2.0.14 (2023-12-10)

- Added real-time video capture from camera in "Vision" mode
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = 'PYGPT'
copyright = '2023, pygpt.net'
author = 'szczyglis-dev, Marcin Szczygliński'
release = '2.0.14'
release = '2.0.15'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
PYGPT v2 - pygpt.net
====================

| **Last update:** 2023-12-10 18:00
| **Last update:** 2023-12-10 21:00
| **Project website:** https://pygpt.net
| **GitHub:** https://github.com/szczyglis-dev/py-gpt
| **PyPI:** https://pypi.org/project/pygpt-net
| **Release:** 2.0.14 (2023-12-10)
| **Release:** 2.0.15 (2023-12-10)
.. toctree::
:maxdepth: 3
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pygpt-net"
version = "2.0.14"
version = "2.0.15"
description = "Desktop AI Assistant powered by GPT-4, GPT-4V, GPT-3, Whisper, TTS and DALL-E 3 with chatbot, assistant, text completion, vision and image generation, real-time internet access, commands and code execution, files upload and download and more"
readme = "README.md"
authors = [{ name = "Marcin Szczygliński", email = "info@pygpt.net" }]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '2.0.14'
VERSION = '2.0.15'
DESCRIPTION = 'Desktop AI Assistant powered by GPT-4, GPT-4V, GPT-3, Whisper, TTS and DALL-E 3 with chatbot, assistant, text completion, ' \
'vision and image generation, real-time internet access, commands and code execution, files upload and download and more'
LONG_DESCRIPTION = 'Package containing a GPT-4, GPT-4V, GPT-3, Whisper, TTS and DALL-E 3 AI desktop assistant with chatbot, ' \
Expand Down
4 changes: 4 additions & 0 deletions src/pygpt_net/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.0.15 (2023-12-10)

- Added camera release / disable on camera off

2.0.14 (2023-12-10)

- Added real-time video capture from camera in "Vision" mode
Expand Down
2 changes: 1 addition & 1 deletion src/pygpt_net/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__copyright__ = "Copyright 2023, Marcin Szczygliński"
__credits__ = ["Marcin Szczygliński"]
__license__ = "MIT"
__version__ = "2.0.14"
__version__ = "2.0.15"
__build__ = "2023.12.10"
__maintainer__ = "Marcin Szczygliński"
__github__ = "https://github.com/szczyglis-dev/py-gpt"
Expand Down
27 changes: 23 additions & 4 deletions src/pygpt_net/core/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, config=None):


class CameraThread(QObject):
finished = Signal(object)
finished = Signal()
destroyed = Signal()
started = Signal()
stopped = Signal()
Expand Down Expand Up @@ -57,16 +57,35 @@ def run(self):
try:
if not self.initialized:
self.setup_camera()
self.started.emit()
self.initialized = True

print("Starting video capture thread....")
while True:
if self.window.is_closing or self.capture is None:
if self.window.is_closing \
or self.capture is None \
or not self.capture.isOpened()\
or self.window.controller.camera.stop:
# release camera
self.release()
self.stopped.emit()
break
_, frame = self.capture.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = cv2.flip(frame, 1)
self.window.controller.camera.frame = frame # update frame
except Exception as e:
print("Camera thread exception:", e)
self.finished.emit(e)

# release camera
self.release()
self.finished.emit()

def release(self):
"""
Release camera
"""
if self.capture is not None and self.capture.isOpened():
self.capture.release()
self.capture = None
self.frame = None
self.initialized = False
33 changes: 32 additions & 1 deletion src/pygpt_net/core/controller/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
# GitHub: https://github.com/szczyglis-dev/py-gpt #
# MIT License #
# Created By : Marcin Szczygliński #
# Updated Date: 2023.12.10 17:00:00 #
# Updated Date: 2023.12.10 21:00:00 #
# ================================================== #
import datetime
import os
import threading
import cv2
from PySide6.QtCore import Slot

from PySide6.QtGui import QImage, QPixmap, Qt
from ..camera import CameraThread
Expand All @@ -30,6 +31,7 @@ def __init__(self, window=None):
self.frame = None
self.thread_started = False
self.is_capture = False
self.stop = False
self.auto = False

def setup(self):
Expand All @@ -45,11 +47,37 @@ def start(self):
"""
if self.thread_started:
return
self.stop = False
thread = CameraThread(window=self.window)
thread.finished.connect(self.handle_stop)
thread.stopped.connect(self.handle_stop)
self.thread = threading.Thread(target=thread.run)
self.thread.start()
self.thread_started = True

def stop_capture(self):
"""
Stop camera thread
"""
if not self.thread_started:
return
self.stop = True

@Slot()
def handle_stop(self):
"""
On stopped
"""
self.thread_started = False
self.thread = None

def blank_screen(self):
"""
Blank screen
"""
self.window.data['video.preview'].video.setPixmap(QPixmap.fromImage(QImage()))
# self.window.data['video.preview'].setVisible(False)

def update(self):
"""
Update camera frame
Expand Down Expand Up @@ -94,6 +122,7 @@ def hide_camera(self):
Hide camera
"""
self.window.data['video.preview'].setVisible(False)
self.stop_capture()

def enable_capture(self):
"""
Expand All @@ -114,6 +143,8 @@ def disable_capture(self):
return
self.is_capture = False
self.window.config.data['vision.capture.enabled'] = False
self.stop_capture()
self.blank_screen()

def toggle(self, state):
"""
Expand Down
8 changes: 4 additions & 4 deletions version.rc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VSVersionInfo(
ffi=FixedFileInfo(
filevers=(2, 0, 13, 0),
prodvers=(2, 0, 13, 0),
filevers=(2, 0, 15, 0),
prodvers=(2, 0, 15, 0),
mask=0x3f,
flags=0x0,
OS=0x4,
Expand All @@ -16,12 +16,12 @@ StringFileInfo(
u'040904B0',
[StringStruct(u'CompanyName', u'pygpt.net'),
StringStruct(u'FileDescription', u'Desktop AI Assistant powered by GPT-4, GPT-3 and DALL-E 3: assistant, chatbot, text completion, image generation and analyze and more'),
StringStruct(u'FileVersion', u'2.0.13'),
StringStruct(u'FileVersion', u'2.0.15'),
StringStruct(u'InternalName', u'Py-GPT'),
StringStruct(u'LegalCopyright', u'(c) 2023 pygpt.net, Marcin Szczygliński'),
StringStruct(u'OriginalFilename', u'Py-GPT.exe'),
StringStruct(u'ProductName', u'pygpt.net'),
StringStruct(u'ProductVersion', u'2.0.13')])
StringStruct(u'ProductVersion', u'2.0.15')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
Expand Down

0 comments on commit ca72f2c

Please sign in to comment.