Spaces:
Sleeping
Sleeping
Commit ·
a68e0ce
1
Parent(s): 64597df
feat: adicionar caixa de texto para texto extraído do PDF
Browse filesCo-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>
199 unmodified lines20020120220320420520620720820921021121221321421518 unmodified lines23423523623723823924026 unmodified lines26726826927027127227318 unmodified lines292293294295296297298199 unmodified linesdef process_pdf(pdf_file, model_name):"""Função principal que processa o PDF e retorna resultados"""if pdf_file is None:return {"error": "Nenhum arquivo enviado"}, pd.DataFrame(), pd.DataFrame(), "❌ Nenhum arquivo enviado"# Extrair texto do PDFtext, metadata = extract_pdf_text(pdf_file)if text is None:return metadata, pd.DataFrame(), pd.DataFrame(), "❌ Erro ao processar PDF"# Adicionar modelo selecionado aos metadadosmetadata["modelo_usado"] = model_name# Extrair referências com LLMllm_references = extract_references_with_llm(text, model_name)18 unmodified linesstatus = f"📊 **Resultados da Extração:**\n- LLM ({model_name}): {llm_count} referências\n- Regex: {regex_count} referências"return metadata, llm_df, regex_df, statusdef create_interface():"""Cria a interface Gradio"""26 unmodified linesextract_btn = gr.Button("🔍 Extrair Referências", variant="primary")with gr.Row():metadata_output = gr.JSON(label="📋 Metadados do Artigo")with gr.Row():with gr.Column():18 unmodified linesextract_btn.click(process_pdf,inputs=[pdf_input, model_dropdown],outputs=[metadata_output, llm_references_output, regex_references_output, status_output])return interface199 unmodified lines20020120220320420520620720820921021121221321421521621718 unmodified lines23623723823924024124226 unmodified lines26927027127227327427527627727827928028128228328428518 unmodified lines304305306307308309310199 unmodified linesdef process_pdf(pdf_file, model_name):"""Função principal que processa o PDF e retorna resultados"""if pdf_file is None:return {"error": "Nenhum arquivo enviado"}, pd.DataFrame(), pd.DataFrame(), "❌ Nenhum arquivo enviado", ""# Extrair texto do PDFtext, metadata = extract_pdf_text(pdf_file)if text is None:return metadata, pd.DataFrame(), pd.DataFrame(), "❌ Erro ao processar PDF", ""# Adicionar modelo selecionado aos metadadosmetadata["modelo_usado"] = model_namemetadata["caracteres_extraidos"] = len(text)metadata["palavras_aproximadas"] = len(text.split())# Extrair referências com LLMllm_references = extract_references_with_llm(text, model_name)18 unmodified linesstatus = f"📊 **Resultados da Extração:**\n- LLM ({model_name}): {llm_count} referências\n- Regex: {regex_count} referências"return metadata, llm_df, regex_df, status, textdef create_interface():"""Cria a interface Gradio"""26 unmodified linesextract_btn = gr.Button("🔍 Extrair Referências", variant="primary")with gr.Row():with gr.Column():metadata_output = gr.JSON(label="📋 Metadados do Artigo")with gr.Column():extracted_text_output = gr.Textbox(label="📄 Texto Extraído do PDF",lines=15,max_lines=20,show_copy_button=True,placeholder="O texto extraído do PDF aparecerá aqui...",interactive=False)with gr.Row():with gr.Column():18 unmodified linesextract_btn.click(process_pdf,inputs=[pdf_input, model_dropdown],outputs=[metadata_output, llm_references_output, regex_references_output, status_output, extracted_text_output])return interface
app.py+17-5