mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2025-01-29 15:44:12 +00:00
fixed uploading large files
This commit is contained in:
parent
9f7bb92db2
commit
8e3e26b563
132
api/__init__.py
132
api/__init__.py
@ -575,63 +575,95 @@ class LoLLMsAPPI(LollmsApplication):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
trace_exception(ex)
|
trace_exception(ex)
|
||||||
|
|
||||||
@socketio.on('send_file')
|
@socketio.on('send_file_chunk')
|
||||||
def send_file(data):
|
def send_file_chunk(data):
|
||||||
ASCIIColors.yellow("Receiving file")
|
|
||||||
|
|
||||||
client_id = request.sid
|
client_id = request.sid
|
||||||
self.connections[client_id]["generated_text"] = ""
|
filename = data['filename']
|
||||||
self.connections[client_id]["cancel_generation"] = False
|
chunk = data['chunk']
|
||||||
|
offset = data['offset']
|
||||||
|
is_last_chunk = data['isLastChunk']
|
||||||
|
chunk_index = data['chunkIndex']
|
||||||
|
path:Path = self.lollms_paths.personal_uploads_path / self.personality.personality_folder_name
|
||||||
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
|
file_path = path / data["filename"]
|
||||||
|
# Save the chunk to the server or process it as needed
|
||||||
|
# For example:
|
||||||
|
if chunk_index==0:
|
||||||
|
with open(file_path, 'wb') as file:
|
||||||
|
file.write(chunk)
|
||||||
|
else:
|
||||||
|
with open(file_path, 'ab') as file:
|
||||||
|
file.write(chunk)
|
||||||
|
|
||||||
if not self.config.use_files:
|
if is_last_chunk:
|
||||||
self.socketio.emit('file_received',
|
print('File received and saved successfully')
|
||||||
{
|
|
||||||
"status":False,
|
|
||||||
"filename":data["filename"],
|
|
||||||
"error":"Couldn't receive file: Verify that file type is compatible with the personality"
|
|
||||||
}, room=client_id
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.personality.setCallback(partial(self.process_chunk,client_id = client_id))
|
|
||||||
ASCIIColors.info("Recovering file from front end")
|
|
||||||
|
|
||||||
path:Path = self.lollms_paths.personal_uploads_path / self.personality.personality_folder_name
|
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
|
||||||
file_path = path / data["filename"]
|
|
||||||
File64BitsManager.b642file(data["fileData"],file_path)
|
|
||||||
if self.personality.processor:
|
if self.personality.processor:
|
||||||
result = self.personality.processor.add_file(file_path, partial(self.process_chunk, client_id=client_id))
|
result = self.personality.processor.add_file(file_path, partial(self.process_chunk, client_id=client_id))
|
||||||
else:
|
else:
|
||||||
result = self.personality.add_file(file_path, partial(self.process_chunk, client_id=client_id))
|
result = self.personality.add_file(file_path, partial(self.process_chunk, client_id=client_id))
|
||||||
if result:
|
|
||||||
self.socketio.emit('file_received',
|
|
||||||
{
|
|
||||||
"status":True,
|
|
||||||
"filename":data["filename"],
|
|
||||||
}, room=client_id
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.socketio.emit('file_received',
|
|
||||||
{
|
|
||||||
"status":False,
|
|
||||||
"filename":data["filename"],
|
|
||||||
"error":"Couldn't receive file: Verify that file type is compatible with the personality"
|
|
||||||
}, room=client_id
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as ex:
|
self.socketio.emit('file_received', {'status': True, 'filename': filename})
|
||||||
ASCIIColors.error(ex)
|
else:
|
||||||
trace_exception(ex)
|
# Request the next chunk from the client
|
||||||
self.socketio.emit('file_received',
|
self.socketio.emit('request_next_chunk', {'offset': offset + len(chunk)})
|
||||||
{
|
|
||||||
"status":False,
|
# @socketio.on('send_file')
|
||||||
"filename":data["filename"],
|
# def send_file(data):
|
||||||
"error":"Couldn't receive file: "+str(ex)
|
# ASCIIColors.yellow("Receiving file")
|
||||||
}, room=client_id
|
|
||||||
)
|
# client_id = request.sid
|
||||||
self.close_message(client_id)
|
# self.connections[client_id]["generated_text"] = ""
|
||||||
|
# self.connections[client_id]["cancel_generation"] = False
|
||||||
|
|
||||||
|
# if not self.config.use_files:
|
||||||
|
# self.socketio.emit('file_received',
|
||||||
|
# {
|
||||||
|
# "status":False,
|
||||||
|
# "filename":data["filename"],
|
||||||
|
# "error":"Couldn't receive file: Verify that file type is compatible with the personality"
|
||||||
|
# }, room=client_id
|
||||||
|
# )
|
||||||
|
# return
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# self.personality.setCallback(partial(self.process_chunk,client_id = client_id))
|
||||||
|
# ASCIIColors.info("Recovering file from front end")
|
||||||
|
|
||||||
|
# path:Path = self.lollms_paths.personal_uploads_path / self.personality.personality_folder_name
|
||||||
|
# path.mkdir(parents=True, exist_ok=True)
|
||||||
|
# file_path = path / data["filename"]
|
||||||
|
# File64BitsManager.b642file(data["fileData"],file_path)
|
||||||
|
# if self.personality.processor:
|
||||||
|
# result = self.personality.processor.add_file(file_path, partial(self.process_chunk, client_id=client_id))
|
||||||
|
# else:
|
||||||
|
# result = self.personality.add_file(file_path, partial(self.process_chunk, client_id=client_id))
|
||||||
|
# if result:
|
||||||
|
# self.socketio.emit('file_received',
|
||||||
|
# {
|
||||||
|
# "status":True,
|
||||||
|
# "filename":data["filename"],
|
||||||
|
# }, room=client_id
|
||||||
|
# )
|
||||||
|
# else:
|
||||||
|
# self.socketio.emit('file_received',
|
||||||
|
# {
|
||||||
|
# "status":False,
|
||||||
|
# "filename":data["filename"],
|
||||||
|
# "error":"Couldn't receive file: Verify that file type is compatible with the personality"
|
||||||
|
# }, room=client_id
|
||||||
|
# )
|
||||||
|
|
||||||
|
# except Exception as ex:
|
||||||
|
# ASCIIColors.error(ex)
|
||||||
|
# trace_exception(ex)
|
||||||
|
# self.socketio.emit('file_received',
|
||||||
|
# {
|
||||||
|
# "status":False,
|
||||||
|
# "filename":data["filename"],
|
||||||
|
# "error":"Couldn't receive file: "+str(ex)
|
||||||
|
# }, room=client_id
|
||||||
|
# )
|
||||||
|
# self.close_message(client_id)
|
||||||
|
|
||||||
@self.socketio.on('cancel_text_generation')
|
@self.socketio.on('cancel_text_generation')
|
||||||
def cancel_text_generation(data):
|
def cancel_text_generation(data):
|
||||||
|
7
app.py
7
app.py
@ -135,10 +135,11 @@ log = logging.getLogger('werkzeug')
|
|||||||
log.setLevel(logging.ERROR)
|
log.setLevel(logging.ERROR)
|
||||||
|
|
||||||
app = Flask("Lollms-WebUI", static_url_path="/static", static_folder="static")
|
app = Flask("Lollms-WebUI", static_url_path="/static", static_folder="static")
|
||||||
|
from flask_compress import Compress
|
||||||
# async_mode='gevent', ping_timeout=1200, ping_interval=120,
|
# async_mode='gevent', ping_timeout=1200, ping_interval=120,
|
||||||
socketio = SocketIO(app, cors_allowed_origins="*", async_mode='threading',engineio_options={'websocket_compression': False, 'websocket_ping_interval': 20, 'websocket_ping_timeout': 120, 'websocket_max_queue': 100})
|
socketio = SocketIO(app, cors_allowed_origins="*", async_mode='gevent', ping_timeout=1200, ping_interval=120)
|
||||||
|
#socketio = SocketIO(app, cors_allowed_origins="*", async_mode='threading',engineio_options={'websocket_compression': True, 'websocket_ping_interval': 20, 'websocket_ping_timeout': 120, 'websocket_max_queue': 100})
|
||||||
|
compress = Compress(app)
|
||||||
app.config['SECRET_KEY'] = 'secret!'
|
app.config['SECRET_KEY'] = 'secret!'
|
||||||
# Set the logging level to WARNING or higher
|
# Set the logging level to WARNING or higher
|
||||||
logging.getLogger('socketio').setLevel(logging.WARNING)
|
logging.getLogger('socketio').setLevel(logging.WARNING)
|
||||||
|
1
mPLUG-Owl
Submodule
1
mPLUG-Owl
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 7f1d5f8148a0c9ea224548dfe0a72a823cdd2eae
|
@ -21,6 +21,8 @@ def run_git_pull():
|
|||||||
submodule_repo = submodule.module()
|
submodule_repo = submodule.module()
|
||||||
submodule_repo.git.checkout('main')
|
submodule_repo.git.checkout('main')
|
||||||
print(f"Checking out main from {submodule}")
|
print(f"Checking out main from {submodule}")
|
||||||
|
submodule.update()
|
||||||
|
print(f"Checking out main from {submodule}")
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(f"Couldn't checkout module {submodule}")
|
print(f"Couldn't checkout module {submodule}")
|
||||||
|
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
4
web/dist/index.html
vendored
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>LoLLMS WebUI - Welcome</title>
|
<title>LoLLMS WebUI - Welcome</title>
|
||||||
<script type="module" crossorigin src="/assets/index-bebc2e4a.js"></script>
|
<script type="module" crossorigin src="/assets/index-925b269b.js"></script>
|
||||||
<link rel="stylesheet" href="/assets/index-234c3c92.css">
|
<link rel="stylesheet" href="/assets/index-9d93b9ab.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
@ -552,42 +552,81 @@ export default {
|
|||||||
this.filesList = []
|
this.filesList = []
|
||||||
this.isFileSentList = []
|
this.isFileSentList = []
|
||||||
},
|
},
|
||||||
send_file(file, next){
|
// send_file(file, next){
|
||||||
const formData = new FormData();
|
// const formData = new FormData();
|
||||||
formData.append('file', file);
|
// formData.append('file', file);
|
||||||
console.log("Uploading file")
|
// console.log("Uploading file")
|
||||||
// Read the file as a data URL and emit it to the server
|
// // Read the file as a data URL and emit it to the server
|
||||||
const reader = new FileReader();
|
// const reader = new FileReader();
|
||||||
reader.onload = () => {
|
// reader.onload = () => {
|
||||||
const data = {
|
// const data = {
|
||||||
filename: file.name,
|
// filename: file.name,
|
||||||
fileData: reader.result,
|
// fileData: reader.result,
|
||||||
};
|
// };
|
||||||
socket.on('file_received',(resp)=>{
|
// socket.on('file_received',(resp)=>{
|
||||||
if(resp.status){
|
// if(resp.status){
|
||||||
console.log(resp.filename)
|
// console.log(resp.filename)
|
||||||
this.isFileSentList[this.filesList.length-1]=true;
|
// this.isFileSentList[this.filesList.length-1]=true;
|
||||||
console.log(this.isFileSentList)
|
// console.log(this.isFileSentList)
|
||||||
this.onShowToastMessage("File uploaded successfully",4,true);
|
// this.onShowToastMessage("File uploaded successfully",4,true);
|
||||||
}
|
// }
|
||||||
else{
|
// else{
|
||||||
this.onShowToastMessage("Couldn't upload file\n"+resp.error,4,false);
|
// this.onShowToastMessage("Couldn't upload file\n"+resp.error,4,false);
|
||||||
try{
|
// try{
|
||||||
this.filesList.removeItem(file)
|
// this.filesList.removeItem(file)
|
||||||
}
|
// }
|
||||||
catch{
|
// catch{
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
socket.off('file_received')
|
// socket.off('file_received')
|
||||||
next()
|
// next()
|
||||||
|
|
||||||
})
|
// })
|
||||||
socket.emit('send_file', data);
|
// console.log("Sending file")
|
||||||
|
// socket.emit('send_file', data);
|
||||||
|
// };
|
||||||
|
// reader.readAsDataURL(file);
|
||||||
|
// },
|
||||||
|
send_file(file, next) {
|
||||||
|
const fileReader = new FileReader();
|
||||||
|
const chunkSize = 24 * 1024; // Chunk size in bytes (e.g., 1MB)
|
||||||
|
let offset = 0;
|
||||||
|
let chunkIndex = 0;
|
||||||
|
fileReader.onloadend = () => {
|
||||||
|
if (fileReader.error) {
|
||||||
|
console.error('Error reading file:', fileReader.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const chunk = fileReader.result;
|
||||||
|
const isLastChunk = offset + chunk.byteLength >= file.size;
|
||||||
|
socket.emit('send_file_chunk', {
|
||||||
|
filename: file.name,
|
||||||
|
chunk: chunk,
|
||||||
|
offset: offset,
|
||||||
|
isLastChunk: isLastChunk,
|
||||||
|
chunkIndex: chunkIndex
|
||||||
|
});
|
||||||
|
offset += chunk.byteLength;
|
||||||
|
chunkIndex++;
|
||||||
|
if (!isLastChunk) {
|
||||||
|
readNextChunk();
|
||||||
|
} else {
|
||||||
|
console.log('File sent successfully');
|
||||||
|
this.isFileSentList[this.filesList.length-1]=true;
|
||||||
|
console.log(this.isFileSentList)
|
||||||
|
this.onShowToastMessage("File uploaded successfully",4,true);
|
||||||
|
next();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
function readNextChunk() {
|
||||||
},
|
const blob = file.slice(offset, offset + chunkSize);
|
||||||
|
fileReader.readAsArrayBuffer(blob);
|
||||||
|
}
|
||||||
|
console.log('Uploading file');
|
||||||
|
readNextChunk();
|
||||||
|
},
|
||||||
makeAnEmptyMessage() {
|
makeAnEmptyMessage() {
|
||||||
this.$emit('createEmptyMessage')
|
this.$emit('createEmptyMessage')
|
||||||
},
|
},
|
||||||
|
@ -10,7 +10,7 @@ import io from 'socket.io-client';
|
|||||||
const URL = process.env.NODE_ENV === "production" ? undefined : (import.meta.env.VITE_LOLLMS_API);
|
const URL = process.env.NODE_ENV === "production" ? undefined : (import.meta.env.VITE_LOLLMS_API);
|
||||||
const socket = new io(URL,{
|
const socket = new io(URL,{
|
||||||
reconnection: true, // Enable reconnection
|
reconnection: true, // Enable reconnection
|
||||||
reconnectionAttempts: 3, // Maximum reconnection attempts
|
reconnectionAttempts: 10, // Maximum reconnection attempts
|
||||||
reconnectionDelay: 1000, // Delay between reconnection attempts (in milliseconds)
|
reconnectionDelay: 1000, // Delay between reconnection attempts (in milliseconds)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit cc80d4f303fc1027b1cbe24b7f6bd8be7e4e7f95
|
Subproject commit 002376c68bb41ac07a363e8d37db557c52e057a1
|
@ -1 +1 @@
|
|||||||
Subproject commit 7b06d5cbddf4cebaca27aad62f399b5f059fbb84
|
Subproject commit ddd8c60e32cc21d4a6a1eec599b29377fbcc5ed5
|
@ -1 +1 @@
|
|||||||
Subproject commit 0f23b00853064b6bff8ba30cc78d0d9c4c0070bb
|
Subproject commit d9400f76f34505b1005a1ed0cc8d82d6443b980d
|
Loading…
x
Reference in New Issue
Block a user