Spaces:
Running
Running
Commit
·
5447dec
1
Parent(s):
f67e1e8
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
|
|
|
|
3 |
|
4 |
# Configure sua chave de API do OpenAI
|
5 |
openai.api_key = "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"
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Interface Gradio
|
21 |
input_text = gr.inputs.Textbox(label="Inserir palavras-chave separadas por vírgulas")
|
@@ -24,11 +40,11 @@ output_text = gr.outputs.Textbox(label="Resultado")
|
|
24 |
|
25 |
def generate_cdu(palavras_chave):
|
26 |
if palavras_chave:
|
27 |
-
return
|
28 |
else:
|
29 |
return ""
|
30 |
|
31 |
title = "Gerador de CDU"
|
32 |
-
description = "Insira
|
33 |
|
34 |
-
gr.Interface(fn=generate_cdu, inputs=input_text, outputs=output_text, title=title, description=description, button_text=button_label).launch()
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
+
import requests
|
4 |
+
import PyPDF2
|
5 |
|
6 |
# Configure sua chave de API do OpenAI
|
7 |
openai.api_key = "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"
|
8 |
|
9 |
+
def buscar_cdu(palavras_chave):
|
10 |
+
# Carregar o arquivo PDF da URL
|
11 |
+
url = "https://huggingface.co/spaces/itacaiunas/gerador-cdu/blob/main/TABELA%20CDU%20DE%20C%C3%93DIGO%20DE%20ASSUNTO.pdf"
|
12 |
+
response = requests.get(url)
|
13 |
+
with open("dados-cdu.pdf", "wb") as file:
|
14 |
+
file.write(response.content)
|
15 |
+
|
16 |
+
# Extrair informações do arquivo PDF
|
17 |
+
classificacoes = extrair_classificacoes("dados-cdu.pdf")
|
18 |
+
|
19 |
+
# Encontrar a classificação relacionada às palavras-chave
|
20 |
+
for palavra_chave in palavras_chave:
|
21 |
+
for classificacao in classificacoes:
|
22 |
+
if palavra_chave.lower() in classificacao.lower():
|
23 |
+
return classificacao
|
24 |
+
|
25 |
+
return "Nenhuma classificação encontrada para as palavras-chave fornecidas."
|
26 |
+
|
27 |
+
def extrair_classificacoes(file_path):
|
28 |
+
classificacoes = []
|
29 |
+
with open(file_path, "rb") as file:
|
30 |
+
reader = PyPDF2.PdfFileReader(file)
|
31 |
+
for page in range(reader.numPages):
|
32 |
+
text = reader.getPage(page).extractText()
|
33 |
+
classificacoes.extend(text.split("\n"))
|
34 |
+
return classificacoes
|
35 |
|
36 |
# Interface Gradio
|
37 |
input_text = gr.inputs.Textbox(label="Inserir palavras-chave separadas por vírgulas")
|
|
|
40 |
|
41 |
def generate_cdu(palavras_chave):
|
42 |
if palavras_chave:
|
43 |
+
return buscar_cdu(palavras_chave.split(","))
|
44 |
else:
|
45 |
return ""
|
46 |
|
47 |
title = "Gerador de CDU"
|
48 |
+
description = "Insira palavras-chave separadas por vírgulas e clique em 'Gerar CDU' para obter a classificação relacionada."
|
49 |
|
50 |
+
gr.Interface(fn=generate_cdu, inputs=input_text, outputs=output_text, title=title, description=description, model_name="gpt-3.5-turbo", button_text=button_label).launch()
|