first commit
This commit is contained in:
0
chats/__init__.py
Normal file
0
chats/__init__.py
Normal file
BIN
chats/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
chats/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
chats/__pycache__/chat_tools.cpython-311.pyc
Normal file
BIN
chats/__pycache__/chat_tools.cpython-311.pyc
Normal file
Binary file not shown.
BIN
chats/__pycache__/streamlit_tools.cpython-311.pyc
Normal file
BIN
chats/__pycache__/streamlit_tools.cpython-311.pyc
Normal file
Binary file not shown.
28
chats/chat_tools.py
Normal file
28
chats/chat_tools.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from colorama import Fore, Back, Style
|
||||
|
||||
|
||||
class MessageManager:
|
||||
|
||||
def create_chat(self, qa):
|
||||
|
||||
# Emoticon de robot
|
||||
ia_emoticon = "\U0001F916" # Emoticon de robot Unicode
|
||||
humano_emoticon = "\U0001F604" # Emoticon de carita feliz Unicode
|
||||
|
||||
# Imprimir el texto en amarillo y negrita con el emoticon de robot
|
||||
|
||||
# Definicimo el mensaje de la IA
|
||||
print(f"{ia_emoticon} " + Style.BRIGHT + Fore.YELLOW +
|
||||
"IA: " + Style.RESET_ALL + "Pregunta algo al documento")
|
||||
while True:
|
||||
input_usuario = input(
|
||||
Style.BRIGHT + Fore.BLUE + f"{humano_emoticon} You: " + Style.RESET_ALL)
|
||||
if input_usuario.lower() == 'salir':
|
||||
break
|
||||
bot_response = qa.invoke({"question": f"{input_usuario}"},
|
||||
return_only_outputs=True)
|
||||
print(f'{ia_emoticon} ' + Style.BRIGHT + Fore.YELLOW +
|
||||
'IA:' + Style.RESET_ALL + f'{bot_response["answer"]}')
|
||||
|
||||
def generate_citations(self):
|
||||
pass
|
||||
33
chats/streamlit_tools.py
Normal file
33
chats/streamlit_tools.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import streamlit as st
|
||||
import os
|
||||
|
||||
# @st.cache_data
|
||||
|
||||
|
||||
def import_file() -> str:
|
||||
# Cargar el archivo pdf
|
||||
archivo = st.file_uploader(
|
||||
'Arrastra o ingresa tu archivo .pdf', type=['.pdf'])
|
||||
nombre_archivo: str = ''
|
||||
# Verificar si se ha cargado un archivo
|
||||
if archivo is not None:
|
||||
|
||||
nombre_archivo = archivo.name
|
||||
# Abrir un archivo en modo escritura binaria ('wb') para guardar el archivo de audio
|
||||
|
||||
with open(f'documents/pdfs/{nombre_archivo}', 'wb') as new_file:
|
||||
# Leer los datos del archivo cargado y escribirlos en el nuevo archivo
|
||||
new_file.write(archivo.read())
|
||||
|
||||
return nombre_archivo
|
||||
|
||||
# Define la función para borrar el caché
|
||||
|
||||
|
||||
def clear_cache():
|
||||
cache_path = os.path.join(st.__path__[0], 'static', 'cache')
|
||||
for root, dirs, files in os.walk(cache_path):
|
||||
for file in files:
|
||||
os.remove(os.path.join(root, file))
|
||||
st.success('Cache limpio exitosamente.')
|
||||
|
||||
Reference in New Issue
Block a user