Spaces:
Running
Running
File size: 1,096 Bytes
54155f3 44870e3 54155f3 44870e3 54155f3 44870e3 54155f3 44870e3 54155f3 24055cd 54155f3 9772c46 54155f3 44870e3 54155f3 44870e3 54155f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from utils.file_reader import file_reader
from rag.RAG import rag
class HandleFiles:
def __init__(self):
pass
def handle_files(self,files,allowed_chars):
try:
result = {}
content,status_code = file_reader.calc_chars(files,allowed_chars)
if(status_code!=200):
return content,status_code
for text_dict in content['clean_contents']:
embedding, status_code = rag.generate_embedding(text_dict['content'])
if(status_code!=200):
return embedding,status_code
result[str(text_dict['id'])] = {
"name": text_dict['name'],
"type": text_dict['type'],
"total_chars": text_dict['total_chars'],
"embedding": embedding['embeddings'],
"chunks": embedding['chunks']
}
return result
except Exception as e:
return {"error": f"an error occured: {e}"}, 500
file_handler = HandleFiles() |