fccoelho aider (anthropic/claude-sonnet-4-20250514) commited on
Commit
a68e0ce
·
1 Parent(s): 64597df

feat: adicionar caixa de texto para texto extraído do PDF

Browse files

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -200,16 +200,18 @@ def extract_references_with_regex(text):
200
  def process_pdf(pdf_file, model_name):
201
  """Função principal que processa o PDF e retorna resultados"""
202
  if pdf_file is None:
203
- return {"error": "Nenhum arquivo enviado"}, pd.DataFrame(), pd.DataFrame(), "❌ Nenhum arquivo enviado"
204
 
205
  # Extrair texto do PDF
206
  text, metadata = extract_pdf_text(pdf_file)
207
 
208
  if text is None:
209
- return metadata, pd.DataFrame(), pd.DataFrame(), "❌ Erro ao processar PDF"
210
 
211
  # Adicionar modelo selecionado aos metadados
212
  metadata["modelo_usado"] = model_name
 
 
213
 
214
  # Extrair referências com LLM
215
  llm_references = extract_references_with_llm(text, model_name)
@@ -234,7 +236,7 @@ def process_pdf(pdf_file, model_name):
234
 
235
  status = f"📊 **Resultados da Extração:**\n- LLM ({model_name}): {llm_count} referências\n- Regex: {regex_count} referências"
236
 
237
- return metadata, llm_df, regex_df, status
238
 
239
  def create_interface():
240
  """Cria a interface Gradio"""
@@ -267,7 +269,17 @@ def create_interface():
267
  extract_btn = gr.Button("🔍 Extrair Referências", variant="primary")
268
 
269
  with gr.Row():
270
- metadata_output = gr.JSON(label="📋 Metadados do Artigo")
 
 
 
 
 
 
 
 
 
 
271
 
272
  with gr.Row():
273
  with gr.Column():
@@ -292,7 +304,7 @@ def create_interface():
292
  extract_btn.click(
293
  process_pdf,
294
  inputs=[pdf_input, model_dropdown],
295
- outputs=[metadata_output, llm_references_output, regex_references_output, status_output]
296
  )
297
 
298
  return interface
 
200
  def process_pdf(pdf_file, model_name):
201
  """Função principal que processa o PDF e retorna resultados"""
202
  if pdf_file is None:
203
+ return {"error": "Nenhum arquivo enviado"}, pd.DataFrame(), pd.DataFrame(), "❌ Nenhum arquivo enviado", ""
204
 
205
  # Extrair texto do PDF
206
  text, metadata = extract_pdf_text(pdf_file)
207
 
208
  if text is None:
209
+ return metadata, pd.DataFrame(), pd.DataFrame(), "❌ Erro ao processar PDF", ""
210
 
211
  # Adicionar modelo selecionado aos metadados
212
  metadata["modelo_usado"] = model_name
213
+ metadata["caracteres_extraidos"] = len(text)
214
+ metadata["palavras_aproximadas"] = len(text.split())
215
 
216
  # Extrair referências com LLM
217
  llm_references = extract_references_with_llm(text, model_name)
 
236
 
237
  status = f"📊 **Resultados da Extração:**\n- LLM ({model_name}): {llm_count} referências\n- Regex: {regex_count} referências"
238
 
239
+ return metadata, llm_df, regex_df, status, text
240
 
241
  def create_interface():
242
  """Cria a interface Gradio"""
 
269
  extract_btn = gr.Button("🔍 Extrair Referências", variant="primary")
270
 
271
  with gr.Row():
272
+ with gr.Column():
273
+ metadata_output = gr.JSON(label="📋 Metadados do Artigo")
274
+ with gr.Column():
275
+ extracted_text_output = gr.Textbox(
276
+ label="📄 Texto Extraído do PDF",
277
+ lines=15,
278
+ max_lines=20,
279
+ show_copy_button=True,
280
+ placeholder="O texto extraído do PDF aparecerá aqui...",
281
+ interactive=False
282
+ )
283
 
284
  with gr.Row():
285
  with gr.Column():
 
304
  extract_btn.click(
305
  process_pdf,
306
  inputs=[pdf_input, model_dropdown],
307
+ outputs=[metadata_output, llm_references_output, regex_references_output, status_output, extracted_text_output]
308
  )
309
 
310
  return interface