Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,10 +19,8 @@ memory = ConversationBufferMemory(memory_key="chat_history", return_messages=Tru
|
|
| 19 |
def carregar_documento_txt(path):
|
| 20 |
loader = TextLoader(path, encoding="latin-1")
|
| 21 |
documentos = loader.load()
|
| 22 |
-
|
| 23 |
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 24 |
documentos_divididos = splitter.split_documents(documentos)
|
| 25 |
-
|
| 26 |
embeddings = HuggingFaceEmbeddings()
|
| 27 |
vectorstore = FAISS.from_documents(documentos_divididos, embeddings)
|
| 28 |
return vectorstore
|
|
@@ -43,18 +41,22 @@ def responder(pergunta):
|
|
| 43 |
|
| 44 |
# 🔹 Interface Gradio
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
-
gr.Markdown("## 🤖 Chat IA com Documento TXT
|
| 47 |
|
| 48 |
-
chatbot = gr.Chatbot()
|
| 49 |
-
entrada = gr.Textbox(placeholder="Digite sua pergunta
|
|
|
|
| 50 |
|
| 51 |
-
def interagir(msg, history
|
| 52 |
resposta = responder(msg)
|
| 53 |
-
history
|
| 54 |
return "", history
|
| 55 |
|
| 56 |
-
entrada.submit(interagir, [entrada,
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
# 🔹 Lança
|
| 59 |
demo.launch(server_name="0.0.0.0", server_port=7860, show_api=False)
|
| 60 |
|
|
|
|
|
|
| 19 |
def carregar_documento_txt(path):
|
| 20 |
loader = TextLoader(path, encoding="latin-1")
|
| 21 |
documentos = loader.load()
|
|
|
|
| 22 |
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 23 |
documentos_divididos = splitter.split_documents(documentos)
|
|
|
|
| 24 |
embeddings = HuggingFaceEmbeddings()
|
| 25 |
vectorstore = FAISS.from_documents(documentos_divididos, embeddings)
|
| 26 |
return vectorstore
|
|
|
|
| 41 |
|
| 42 |
# 🔹 Interface Gradio
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
+
gr.Markdown("## 🤖 Chat IA com Documento TXT")
|
| 45 |
|
| 46 |
+
chatbot = gr.Chatbot(label="Chat com Documento")
|
| 47 |
+
entrada = gr.Textbox(placeholder="Digite sua pergunta e aperte Enter ou clique em Enviar", show_label=False)
|
| 48 |
+
estado_chat = gr.State([]) # Histórico local do chat
|
| 49 |
|
| 50 |
+
def interagir(msg, history):
|
| 51 |
resposta = responder(msg)
|
| 52 |
+
history = history + [(msg, resposta)]
|
| 53 |
return "", history
|
| 54 |
|
| 55 |
+
entrada.submit(interagir, [entrada, estado_chat], [entrada, chatbot])
|
| 56 |
+
enviar_btn = gr.Button("Enviar")
|
| 57 |
+
enviar_btn.click(interagir, [entrada, estado_chat], [entrada, chatbot])
|
| 58 |
|
| 59 |
+
# 🔹 Lança a interface
|
| 60 |
demo.launch(server_name="0.0.0.0", server_port=7860, show_api=False)
|
| 61 |
|
| 62 |
+
|