Spaces:
Running
Running
Commit
·
1f073b5
1
Parent(s):
025996e
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,21 @@
|
|
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 |
-
# Função para obter o texto do arquivo PDF
|
10 |
-
def extrair_texto_pdf(
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
17 |
-
text = ""
|
18 |
-
for page in pdf_reader.pages:
|
19 |
-
text += page.extract_text()
|
20 |
-
pdf_file.close()
|
21 |
-
|
22 |
return text
|
23 |
|
24 |
def gerar_cdu(palavras_chave):
|
25 |
-
texto_base = extrair_texto_pdf(
|
26 |
prompt = f"analise as palavras-chave: {palavras_chave} e retorne com o número de Classificação Decimal Universal (CDU) mais relacionado com as palavras-chave. Dados da base: {texto_base}"
|
27 |
response = openai.Completion.create(
|
28 |
model="text-davinci-003",
|
@@ -49,5 +42,4 @@ def generate_cdu(palavras_chave):
|
|
49 |
title = "Gerador de CDU"
|
50 |
description = "Insira palavras-chave separadas por vírgulas e clique em 'Gerar CDU' para obter a classificação relacionada."
|
51 |
|
52 |
-
gr.Interface(fn=generate_cdu, inputs=input_text, outputs=output_text, title=title, description=description
|
53 |
-
|
|
|
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)
|
12 |
+
text = ""
|
13 |
+
for page in pdf_reader.pages:
|
14 |
+
text += page.extract_text()
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
return text
|
16 |
|
17 |
def gerar_cdu(palavras_chave):
|
18 |
+
texto_base = extrair_texto_pdf()
|
19 |
prompt = f"analise as palavras-chave: {palavras_chave} e retorne com o número de Classificação Decimal Universal (CDU) mais relacionado com as palavras-chave. Dados da base: {texto_base}"
|
20 |
response = openai.Completion.create(
|
21 |
model="text-davinci-003",
|
|
|
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()
|
|