File size: 2,132 Bytes
f92da22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/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)