Spaces:
Sleeping
Sleeping
Felipe Silva
commited on
Commit
·
96114f2
1
Parent(s):
045801f
Inserindo docs sim
Browse files
app.py
CHANGED
|
@@ -49,13 +49,14 @@ def ask_question(texto_extraido, question):
|
|
| 49 |
# resposta = rag_chain.run(question)
|
| 50 |
response = rag_chain({"query": question})
|
| 51 |
resposta = response["result"]
|
|
|
|
| 52 |
|
| 53 |
-
return resposta
|
| 54 |
|
| 55 |
def launch_app():
|
| 56 |
with gr.Blocks(title="RAG", theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray", neutral_hue="slate")) as demo:
|
| 57 |
-
gr.Markdown("# Retrieval Augmented Generation")
|
| 58 |
-
gr.Markdown("
|
| 59 |
gr.Markdown(
|
| 60 |
"🐶 Faça o upload do seu arquivo e pergunte qualquer coisa a ele! Este código é open source e disponível [aqui](https://github.com/FelipeErmeson) no GitHub. 😁"
|
| 61 |
)
|
|
@@ -63,14 +64,15 @@ def launch_app():
|
|
| 63 |
with gr.Row():
|
| 64 |
with gr.Column():
|
| 65 |
file_input = gr.File(label="Upload da Imagem ou PDF", file_types=[".png", ".jpg", ".jpeg", ".pdf"])
|
| 66 |
-
extracted_text = gr.Textbox(label="Texto extraído", lines=
|
| 67 |
with gr.Column():
|
| 68 |
question_input = gr.Textbox(label="📌 Faça uma pergunta ao seu documento!")
|
| 69 |
-
answer_output = gr.Textbox(label="🎩 Resposta", lines=
|
|
|
|
| 70 |
|
| 71 |
# Conecta funções
|
| 72 |
file_input.change(fn=process_file, inputs=file_input, outputs=extracted_text)
|
| 73 |
-
question_input.submit(fn=ask_question, inputs=[extracted_text, question_input], outputs=answer_output)
|
| 74 |
|
| 75 |
demo.launch()
|
| 76 |
|
|
|
|
| 49 |
# resposta = rag_chain.run(question)
|
| 50 |
response = rag_chain({"query": question})
|
| 51 |
resposta = response["result"]
|
| 52 |
+
docs_text = "\n\n".join([doc['page_content'] for doc in response["source_documents"]])
|
| 53 |
|
| 54 |
+
return resposta, docs_text
|
| 55 |
|
| 56 |
def launch_app():
|
| 57 |
with gr.Blocks(title="RAG", theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray", neutral_hue="slate")) as demo:
|
| 58 |
+
gr.Markdown("# 🚀 Retrieval Augmented Generation - RAG")
|
| 59 |
+
gr.Markdown("### ⚙️ Pergunte qualquer coisa para seu arquivo.")
|
| 60 |
gr.Markdown(
|
| 61 |
"🐶 Faça o upload do seu arquivo e pergunte qualquer coisa a ele! Este código é open source e disponível [aqui](https://github.com/FelipeErmeson) no GitHub. 😁"
|
| 62 |
)
|
|
|
|
| 64 |
with gr.Row():
|
| 65 |
with gr.Column():
|
| 66 |
file_input = gr.File(label="Upload da Imagem ou PDF", file_types=[".png", ".jpg", ".jpeg", ".pdf"])
|
| 67 |
+
extracted_text = gr.Textbox(label="🌍 Texto extraído", lines=30)
|
| 68 |
with gr.Column():
|
| 69 |
question_input = gr.Textbox(label="📌 Faça uma pergunta ao seu documento!")
|
| 70 |
+
answer_output = gr.Textbox(label="🎩 Resposta", lines=15)
|
| 71 |
+
docs_sim = gr.Textbox(label="📎 Documentos similares a sua pergunta.", lines=15)
|
| 72 |
|
| 73 |
# Conecta funções
|
| 74 |
file_input.change(fn=process_file, inputs=file_input, outputs=extracted_text)
|
| 75 |
+
question_input.submit(fn=ask_question, inputs=[extracted_text, question_input], outputs=[answer_output, docs_sim])
|
| 76 |
|
| 77 |
demo.launch()
|
| 78 |
|