DHEIVER commited on
Commit
7f29224
·
verified ·
1 Parent(s): 978e58d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client
3
+ import PyPDF2
4
+
5
+ # Função para extrair texto de um PDF
6
+ def extract_text_from_pdf(pdf_path):
7
+ with open(pdf_path, 'rb') as file:
8
+ reader = PyPDF2.PdfFileReader(file)
9
+ text = ''
10
+ for page_num in range(reader.numPages):
11
+ page = reader.getPage(page_num)
12
+ text += page.extract_text()
13
+ return text
14
+
15
+ # Função para gerar parecer usando o modelo de linguagem
16
+ def generate_analysis(text):
17
+ client = Client("yuntian-deng/ChatGPT")
18
+ result = client.predict(
19
+ inputs=text,
20
+ top_p=1,
21
+ temperature=1,
22
+ chat_counter=0,
23
+ chatbot=[],
24
+ api_name="/predict"
25
+ )
26
+ return result
27
+
28
+ # Função principal para a interface
29
+ def analyze_pdf(pdf_file):
30
+ text = extract_text_from_pdf(pdf_file.name)
31
+ analysis = generate_analysis(text)
32
+ return analysis
33
+
34
+ # Interface Gradio
35
+ iface = gr.Interface(
36
+ fn=analyze_pdf,
37
+ inputs=gr.File(label="Upload PDF"),
38
+ outputs=gr.Textbox(label="Parecer Gerado"),
39
+ title="Sistema de Análise de PDF com RAG",
40
+ description="Faça upload de um PDF para gerar um parecer."
41
+ )
42
+
43
+ iface.launch()