Seicas commited on
Commit
f9b22e5
·
verified ·
1 Parent(s): 4a14d8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -24
app.py CHANGED
@@ -10,6 +10,7 @@ from asr import transcribe_file
10
  from diarization import diarize_segments
11
  from privacy import MedicalPrivacyProcessor
12
  from config import settings
 
13
 
14
  # HuggingFace token'ını ayarla
15
  HF_TOKEN = os.getenv("HF_TOKEN", "")
@@ -60,36 +61,54 @@ css = """
60
  .tips {background: #e7f5ff; padding: 15px; border-radius: 5px; margin-top: 20px;}
61
  """
62
 
63
- def process_audio(audio_file, is_pediatrics=True):
64
- """Process audio with improved error handling"""
65
- try:
66
- # Clean audio
67
- cleaned_audio = clean_audio(audio_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- # Transcribe
70
- transcription = transcribe_file(cleaned_audio)
 
71
 
72
- # Diarize
73
- diarization = diarize_segments(transcription["segments"])
 
74
 
75
- # Process text
76
- nlp = load_spacy_model()
77
- processed_text = process_text(transcription, nlp, is_pediatrics)
 
 
 
 
 
78
 
79
- return {
80
- "transcription": transcription,
81
- "diarization": diarization,
82
- "processed_text": processed_text
83
- }
84
 
85
  except Exception as e:
86
- print(f"Error processing audio: {e}")
87
- return {
88
- "error": str(e),
89
- "transcription": "",
90
- "diarization": [],
91
- "processed_text": ""
92
- }
93
 
94
  # Ana arayüz
95
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"), css=css) as demo:
 
10
  from diarization import diarize_segments
11
  from privacy import MedicalPrivacyProcessor
12
  from config import settings
13
+ from typing import Tuple, Dict
14
 
15
  # HuggingFace token'ını ayarla
16
  HF_TOKEN = os.getenv("HF_TOKEN", "")
 
61
  .tips {background: #e7f5ff; padding: 15px; border-radius: 5px; margin-top: 20px;}
62
  """
63
 
64
+ def process_audio(
65
+ audio_path: str,
66
+ do_diarize: bool = True,
67
+ do_enhance: bool = True,
68
+ do_anonymize: bool = True
69
+ ) -> Tuple[str, Dict]:
70
+ """
71
+ Ses dosyasını işleyip transkripsiyon yapar.
72
+
73
+ Args:
74
+ audio_path: Ses dosyasının yolu
75
+ do_diarize: Konuşmacı ayrımı yapılsın mı?
76
+ do_enhance: Ses iyileştirme yapılsın mı?
77
+ do_anonymize: Kişisel veriler anonimleştirilsin mi?
78
+
79
+ Returns:
80
+ Tuple[str, Dict]: (Transkripsiyon metni, JSON sonuç)
81
+ """
82
+ if not audio_path:
83
+ return "Lütfen bir ses dosyası yükleyin.", {}
84
 
85
+ try:
86
+ # Ses dosyasını yükle
87
+ audio = Audio.from_file(audio_path)
88
 
89
+ # Ses iyileştirme
90
+ if do_enhance:
91
+ audio = enhance_audio(audio)
92
 
93
+ # Konuşmacı ayrımı
94
+ if do_diarize:
95
+ diarization = diarize_speakers(audio)
96
+ else:
97
+ diarization = None
98
+
99
+ # Transkripsiyon
100
+ result = transcribe_audio(audio, diarization)
101
 
102
+ # Anonimleştirme
103
+ if do_anonymize:
104
+ result = anonymize_personal_info(result)
105
+
106
+ return result["text"], result
107
 
108
  except Exception as e:
109
+ error_msg = f"İşlem sırasında bir hata oluştu: {str(e)}"
110
+ print(error_msg)
111
+ return error_msg, {}
 
 
 
 
112
 
113
  # Ana arayüz
114
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"), css=css) as demo: