| |
| """ |
| Interface Gradio : Agent NER médical + Mapper |
| Input transcription → Extraction → Mapping → Rapport |
| """ |
| import gradio as gr |
| from type3_extract_entities import MedicalNERAgent |
| from medical_template3_mapper import MedicalTemplateMapper |
| from type3_preprocessing import MedicalTranscriptionProcessor, AZURE_OPENAI_DEPLOYMENT |
| from post_processing import post_process_medical_report |
| def process_transcription(transcription: str): |
| try: |
| |
| processor = MedicalTranscriptionProcessor(AZURE_OPENAI_DEPLOYMENT) |
| result = processor.process_transcription(transcription) |
| corrected_transcription=result.final_corrected_text |
| |
| |
| agent = MedicalNERAgent() |
| extracted_data = agent.extract_medical_entities(corrected_transcription) |
| extraction_report = agent.print_extraction_report(extracted_data) |
|
|
| |
| mapper = MedicalTemplateMapper() |
| mapping_result = mapper.map_extracted_data_to_template(extracted_data) |
| |
| mapping_report = mapper.template |
|
|
| |
| rapport_final = mapping_result.filled_template |
|
|
| |
| cleaned_report = post_process_medical_report(rapport_final) |
|
|
| return corrected_transcription,extraction_report, mapping_report, cleaned_report |
| except Exception as e: |
| return f"Erreur: {e}", "", "" |
|
|
| |
| demo = gr.Interface( |
| fn=process_transcription, |
| inputs=gr.Textbox(lines=15, label="Transcription médicale"), |
| outputs=[ |
| gr.Textbox(lines=20, label="🔬 Crorrection de la transcription"), |
| gr.Textbox(lines=20, label="📋 Extraction structurée"), |
| gr.Textbox(lines=20, label="📋 Rapport à remplir (Mapping)"), |
| gr.Textbox(lines=20, label="✅ Compte-rendu structuré final"), |
| ], |
| title="🏥 Génération de comptes-rendus structurés", |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch(share=True) |
|
|