Spaces:
Running
on
Zero
Running
on
Zero
Felipe Silva
commited on
Commit
·
b9e4562
1
Parent(s):
aa32ce9
Ajustando github
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import spaces
|
|
| 3 |
import torch
|
| 4 |
import os
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
-
from utils import read_file_pdf, fix_type, extract_content_in_pdf, doc_converter, EXTENSIONS_FILES, EXTENSIONS_IMG_FILES
|
| 7 |
from rag_utils import create_split_doc, store_docs, create_rag_chain
|
| 8 |
import config
|
| 9 |
|
|
@@ -26,7 +26,7 @@ config.local_emb_path = snapshot_download(
|
|
| 26 |
|
| 27 |
def process_file(file):
|
| 28 |
if file is None:
|
| 29 |
-
return
|
| 30 |
|
| 31 |
file_size = os.path.getsize(file)
|
| 32 |
if file_size > MAX_FILE_SIZE:
|
|
@@ -34,7 +34,7 @@ def process_file(file):
|
|
| 34 |
|
| 35 |
texto_extraido = doc_converter(file)
|
| 36 |
if texto_extraido is None:
|
| 37 |
-
return
|
| 38 |
|
| 39 |
return texto_extraido
|
| 40 |
|
|
@@ -54,7 +54,7 @@ def ask_question(texto_extraido, question):
|
|
| 54 |
return resposta, docs_text
|
| 55 |
|
| 56 |
def update_ask_button(extracted_text, question):
|
| 57 |
-
if extracted_text and question.strip():
|
| 58 |
return gr.update(interactive=True)
|
| 59 |
return gr.update(interactive=False)
|
| 60 |
|
|
@@ -63,7 +63,7 @@ def launch_app():
|
|
| 63 |
gr.Markdown("# 🚀 Retrieval Augmented Generation - RAG")
|
| 64 |
gr.Markdown("### ⚙️ Pergunte qualquer coisa para seu arquivo.")
|
| 65 |
gr.Markdown(
|
| 66 |
-
"🐶 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. 😁"
|
| 67 |
)
|
| 68 |
|
| 69 |
with gr.Row():
|
|
|
|
| 3 |
import torch
|
| 4 |
import os
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
+
from utils import read_file_pdf, fix_type, extract_content_in_pdf, doc_converter, EXTENSIONS_FILES, EXTENSIONS_IMG_FILES, MSG_NENHUM_ARQUIVO_ENVIADO, MSG_TEXTO_NAO_EXTRAIDO
|
| 7 |
from rag_utils import create_split_doc, store_docs, create_rag_chain
|
| 8 |
import config
|
| 9 |
|
|
|
|
| 26 |
|
| 27 |
def process_file(file):
|
| 28 |
if file is None:
|
| 29 |
+
return MSG_NENHUM_ARQUIVO_ENVIADO
|
| 30 |
|
| 31 |
file_size = os.path.getsize(file)
|
| 32 |
if file_size > MAX_FILE_SIZE:
|
|
|
|
| 34 |
|
| 35 |
texto_extraido = doc_converter(file)
|
| 36 |
if texto_extraido is None:
|
| 37 |
+
return MSG_TEXTO_NAO_EXTRAIDO
|
| 38 |
|
| 39 |
return texto_extraido
|
| 40 |
|
|
|
|
| 54 |
return resposta, docs_text
|
| 55 |
|
| 56 |
def update_ask_button(extracted_text, question):
|
| 57 |
+
if extracted_text and MSG_NENHUM_ARQUIVO_ENVIADO not in extracted_text and MSG_TEXTO_NAO_EXTRAIDO not in extracted_text and question.strip():
|
| 58 |
return gr.update(interactive=True)
|
| 59 |
return gr.update(interactive=False)
|
| 60 |
|
|
|
|
| 63 |
gr.Markdown("# 🚀 Retrieval Augmented Generation - RAG")
|
| 64 |
gr.Markdown("### ⚙️ Pergunte qualquer coisa para seu arquivo.")
|
| 65 |
gr.Markdown(
|
| 66 |
+
"🐶 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/General-RAG) no GitHub. 😁"
|
| 67 |
)
|
| 68 |
|
| 69 |
with gr.Row():
|
utils.py
CHANGED
|
@@ -8,6 +8,9 @@ EXTENSIONS_IMG_FILES = ['jpeg', 'jpg', 'png']
|
|
| 8 |
EXTENSIONS_FILES = ['pdf']
|
| 9 |
EXTENSIONS_ALLOWED = EXTENSIONS_IMG_FILES + EXTENSIONS_FILES
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Max dimensions for processing
|
| 12 |
MAX_IMAGE_SIZE = 2000 # pixels
|
| 13 |
|
|
|
|
| 8 |
EXTENSIONS_FILES = ['pdf']
|
| 9 |
EXTENSIONS_ALLOWED = EXTENSIONS_IMG_FILES + EXTENSIONS_FILES
|
| 10 |
|
| 11 |
+
MSG_NENHUM_ARQUIVO_ENVIADO = 'Nenhum arquivo enviado.'
|
| 12 |
+
MSG_TEXTO_NAO_EXTRAIDO = "Não foi possível extrair o texto."
|
| 13 |
+
|
| 14 |
# Max dimensions for processing
|
| 15 |
MAX_IMAGE_SIZE = 2000 # pixels
|
| 16 |
|