Spaces:
Running
Running
Commit
·
cf080e7
1
Parent(s):
1f073b5
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
import openai
|
3 |
import PyPDF2
|
4 |
|
5 |
-
# Configure sua chave de API do OpenAI
|
6 |
-
openai.api_key = "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"
|
7 |
-
|
8 |
-
# Função para obter o texto do arquivo PDF
|
9 |
def extrair_texto_pdf():
|
10 |
with open("dados-cdu.pdf", "rb") as pdf_file:
|
11 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
@@ -14,19 +9,22 @@ def extrair_texto_pdf():
|
|
14 |
text += page.extract_text()
|
15 |
return text
|
16 |
|
17 |
-
def
|
18 |
texto_base = extrair_texto_pdf()
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
)
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
# Interface Gradio
|
32 |
input_text = gr.inputs.Textbox(label="Inserir palavras-chave separadas por vírgulas")
|
@@ -35,11 +33,12 @@ output_text = gr.outputs.Textbox(label="Resultado")
|
|
35 |
|
36 |
def generate_cdu(palavras_chave):
|
37 |
if palavras_chave:
|
38 |
-
|
|
|
39 |
else:
|
40 |
-
return
|
41 |
|
42 |
title = "Gerador de CDU"
|
43 |
description = "Insira palavras-chave separadas por vírgulas e clique em 'Gerar CDU' para obter a classificação relacionada."
|
44 |
|
45 |
-
gr.Interface(fn=generate_cdu, inputs=input_text, outputs=output_text, title=title, description=description).launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import PyPDF2
|
3 |
|
|
|
|
|
|
|
|
|
4 |
def extrair_texto_pdf():
|
5 |
with open("dados-cdu.pdf", "rb") as pdf_file:
|
6 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
|
|
9 |
text += page.extract_text()
|
10 |
return text
|
11 |
|
12 |
+
def consultar_cdu(palavra_chave):
|
13 |
texto_base = extrair_texto_pdf()
|
14 |
+
palavras_chave_encontradas = []
|
15 |
+
linhas = texto_base.split("\n")
|
16 |
+
for linha in linhas:
|
17 |
+
if palavra_chave.lower() in linha.lower():
|
18 |
+
palavras_chave_encontradas.append(linha)
|
19 |
+
return palavras_chave_encontradas
|
20 |
+
|
21 |
+
def gerar_cdu(palavras_chave):
|
22 |
+
palavras_chave = [palavra.strip() for palavra in palavras_chave.split(",")]
|
23 |
+
resultados = {}
|
24 |
+
for palavra_chave in palavras_chave:
|
25 |
+
cdu_encontrada = consultar_cdu(palavra_chave)
|
26 |
+
resultados[palavra_chave] = cdu_encontrada
|
27 |
+
return resultados
|
28 |
|
29 |
# Interface Gradio
|
30 |
input_text = gr.inputs.Textbox(label="Inserir palavras-chave separadas por vírgulas")
|
|
|
33 |
|
34 |
def generate_cdu(palavras_chave):
|
35 |
if palavras_chave:
|
36 |
+
resultados = gerar_cdu(palavras_chave)
|
37 |
+
return resultados
|
38 |
else:
|
39 |
+
return {}
|
40 |
|
41 |
title = "Gerador de CDU"
|
42 |
description = "Insira palavras-chave separadas por vírgulas e clique em 'Gerar CDU' para obter a classificação relacionada."
|
43 |
|
44 |
+
gr.Interface(fn=generate_cdu, inputs=input_text, outputs=output_text, title=title, description=description).launch()
|