pipeline2 / app.py
Nourhenem's picture
initial commit
f92da22 verified
raw
history blame
2.13 kB
#!/usr/bin/env python3
"""
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:
#Étape 1 correction asr
processor = MedicalTranscriptionProcessor(AZURE_OPENAI_DEPLOYMENT)
result = processor.process_transcription(transcription)
corrected_transcription=result.final_corrected_text
# Étape 1 : Extraction
agent = MedicalNERAgent()
extracted_data = agent.extract_medical_entities(corrected_transcription)
extraction_report = agent.print_extraction_report(extracted_data)
# Étape 2 : Mapping vers template
mapper = MedicalTemplateMapper()
mapping_result = mapper.map_extracted_data_to_template(extracted_data)
#mapping_report = mapper.print_mapping_report(mapping_result)
mapping_report = mapper.template
# Étape 3 : Rapport final rempli
rapport_final = mapping_result.filled_template
#Étape 4: nettoyage du rapport
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}", "", ""
# Interface Gradio
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)