Fixed language problem, added refresh and take photo

This commit is contained in:
Saifeddine ALOUI 2023-12-12 22:14:08 +01:00
parent 1158b31968
commit 973c9a1a21
11 changed files with 329 additions and 257 deletions

View File

@ -19,7 +19,7 @@ from lollms.paths import LollmsPaths
from lollms.helpers import ASCIIColors, trace_exception
from lollms.com import NotificationType, NotificationDisplayType, LoLLMsCom
from lollms.app import LollmsApplication
from lollms.utilities import File64BitsManager, PromptReshaper
from lollms.utilities import File64BitsManager, PromptReshaper, PackageManager, find_first_available_file_index
from lollms.media import WebcamImageSender, AudioRecorder
from safe_store import TextVectorizer, VectorizationMethod, VisualizationMethod
import threading
@ -36,6 +36,7 @@ import string
import requests
from datetime import datetime
from typing import List, Tuple
import time
def terminate_thread(thread):
if thread:
@ -222,6 +223,43 @@ class LoLLMsAPI(LollmsApplication):
ASCIIColors.error(f'Client {request.sid} disconnected')
@socketio.on('take_picture')
def take_picture():
try:
if not PackageManager.check_package_installed("cv2"):
PackageManager.install_package("opencv-python")
import cv2
cap = cv2.VideoCapture(0)
n = time.time()
while(time.time()-n<2):
_, frame = cap.read()
_, frame = cap.read()
cap.release()
self.info("Shot taken")
cam_shot_path = self.lollms_paths.personal_uploads_path/"camera_shots"
cam_shot_path.mkdir(parents=True, exist_ok=True)
filename = find_first_available_file_index(cam_shot_path, "cam_shot_", extension=".png")
save_path = cam_shot_path/f"cam_shot_{filename}.png" # Specify the desired folder path
try:
cv2.imwrite(str(save_path), frame)
if not self.personality.processor is None:
self.personality.processor.add_file(save_path, partial(self.process_chunk, client_id = request.sid))
# File saved successfully
socketio.emit('picture_taken', {'status':True, 'progress': 100})
else:
self.personality.add_file(save_path, partial(self.process_chunk, client_id = request.sid))
# File saved successfully
socketio.emit('picture_taken', {'status':True, 'progress': 100})
except Exception as e:
# Error occurred while saving the file
socketio.emit('picture_taken', {'status':False, 'error': str(e)})
except Exception as ex:
trace_exception(ex)
self.error("Couldn't use the webcam")
@socketio.on('start_webcam_video_stream')
def start_webcam_video_stream():

1
app.py
View File

@ -2277,6 +2277,7 @@ try:
def p_select_personality(self):
ASCIIColors.info("Selecting personality")
data = request.get_json()
id = data['id']
print(f"- Selecting active personality {id} ...",end="")

8
web/dist/assets/index-2a99fe15.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-da6af66f.js"></script>
<link rel="stylesheet" href="/assets/index-6e0a42ab.css">
<script type="module" crossorigin src="/assets/index-f86549f0.js"></script>
<link rel="stylesheet" href="/assets/index-2a99fe15.css">
</head>
<body>
<div id="app"></div>

View File

@ -229,6 +229,12 @@
class="w-6 hover:text-secondary duration-75 active:scale-90 cursor-pointer"
>
<i data-feather="mic"></i>
</button>
<button type="button" @click.stop="takePicture" title="take a shot from camera"
class=" w-6 hover:text-secondary duration-75 active:scale-90">
<i data-feather="camera"></i>
</button>
<button v-if="!loading" type="button" @click="makeAnEmptyUserMessage" title="New empty user message"
class=" w-6 text-blue-400 hover:text-secondary duration-75 active:scale-90">
@ -523,8 +529,10 @@ export default {
//this.settingsChanged = true
if (pers.isMounted && this.$store.state.config.personalities.includes(pers.full_path)) {
const pers_path = pers.language===null?pers.full_path:pers.full_path+':'+pers.language
console.log("pers_path",pers_path)
console.log("this.$store.state.config.personalities",this.$store.state.config.personalities)
if (this.$store.state.config.personalities.includes(pers_path)) {
const res = await this.select_personality(pers)
console.log('pers is mounted', res)
@ -537,8 +545,6 @@ export default {
} else {
console.log('mounting pers')
this.mountPersonality(pers)
}
this.$emit('personalitySelected')
@ -554,7 +560,9 @@ export default {
},
async select_personality(pers) {
if (!pers) { return { 'status': false, 'error': 'no personality - select_personality' } }
const id = this.$store.state.config.personalities.findIndex(item => item === pers.full_path)
const pers_path = pers.language===null?pers.full_path:pers.full_path+':'+pers.language
console.log("Selecting personality ",pers_path)
const id = this.$store.state.config.personalities.findIndex(item => item === pers_path)
const obj = {
id: id
@ -761,6 +769,18 @@ export default {
sendCMDEvent(cmd){
this.$emit('sendCMDEvent', cmd)
},
takePicture(){
socket.emit('take_picture')
socket.on('picture_taken',()=>{
axios.get('/get_current_personality_files_list').then(res=>{
this.filesList = res.data.files;
this.isFileSentList= res.data.files.map(file => {
return true;
});
console.log(`Files recovered: ${this.filesList}`)
})
});
},
submitOnEnter(event) {
if(!this.loading){
if (event.which === 13) {

View File

@ -154,7 +154,7 @@
</MarkdownRenderer>
<div >
<textarea v-if="message.open" ref="mdTextarea" @keydown.tab.prevent="insertTab"
class="block p-2.5 w-full text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 overflow-y-scroll flex flex-col shadow-lg p-10 pt-0 overflow-y-scroll w-full dark:bg-bg-dark scrollbar-thin scrollbar-track-bg-light-tone scrollbar-thumb-bg-light-tone-panel hover:scrollbar-thumb-primary dark:scrollbar-track-bg-dark-tone dark:scrollbar-thumb-bg-dark-tone-panel dark:hover:scrollbar-thumb-primary active:scrollbar-thumb-secondary"
class="block min-h-[900px] p-2.5 w-full text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 overflow-y-scroll flex flex-col shadow-lg p-10 pt-0 overflow-y-scroll dark:bg-bg-dark scrollbar-thin scrollbar-track-bg-light-tone scrollbar-thumb-bg-light-tone-panel hover:scrollbar-thumb-primary dark:scrollbar-track-bg-dark-tone dark:scrollbar-thumb-bg-dark-tone-panel dark:hover:scrollbar-thumb-primary active:scrollbar-thumb-secondary"
:rows="4"
:style="{ minHeight: mdRenderHeight + `px` }" placeholder="Enter message here..."
v-model="message.content">

View File

@ -35,6 +35,12 @@
<div v-if="!isConnected" title="Connection status: Not connected" class="text-red-500 cursor-pointer">
<i data-feather="zap-off"></i>
</div>
<a href="#" @click="refreshPage">
<div class="text-2xl hover:text-primary duration-150" title="refresh page">
<i data-feather="refresh-ccw"></i>
</div>
</a>
<a href="https://github.com/ParisNeo/lollms-webui" target="_blank">
<div class="text-2xl hover:text-primary duration-150" title="Visit repository page">
@ -142,6 +148,10 @@ export default {
this.systemTheme = window.matchMedia("prefers-color-scheme: dark").matches;
},
methods: {
refreshPage(event) {
event.preventDefault();
window.location.reload();
},
// codeBlockTheme(theme) {
// const styleDark = document.createElement('link');
// styleDark.type = "text/css";

View File

@ -239,6 +239,9 @@ export const store = createStore({
const parts = personality.split(':');
item.language = parts[1];
}
else{
item.language = null
}
}
}
// if (isMounted) {

@ -1 +1 @@
Subproject commit 50ef86ced90019932690d5816fe54efc7e99c73e
Subproject commit b024a4ac7e11d105e730431bb776628772ee910e