Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ 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", "")
|
@@ -80,35 +81,46 @@ def process_audio(
|
|
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ı
|
87 |
-
|
|
|
|
|
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(
|
96 |
else:
|
97 |
diarization = None
|
98 |
|
99 |
# Transkripsiyon
|
100 |
-
result = transcribe_audio(
|
101 |
|
102 |
# Anonimleştirme
|
103 |
if do_anonymize:
|
104 |
result = anonymize_personal_info(result)
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
11 |
from privacy import MedicalPrivacyProcessor
|
12 |
from config import settings
|
13 |
from typing import Tuple, Dict
|
14 |
+
from pydub import AudioSegment
|
15 |
|
16 |
# HuggingFace token'ını ayarla
|
17 |
HF_TOKEN = os.getenv("HF_TOKEN", "")
|
|
|
81 |
Tuple[str, Dict]: (Transkripsiyon metni, JSON sonuç)
|
82 |
"""
|
83 |
if not audio_path:
|
84 |
+
return "Lütfen bir ses dosyası yükleyin.", {"error": "Dosya yüklenmedi"}
|
85 |
|
86 |
try:
|
87 |
+
# Ses dosyasını WAV formatına çevir
|
88 |
+
base, ext = os.path.splitext(audio_path)
|
89 |
+
wav_path = base + ".wav"
|
90 |
+
audio = AudioSegment.from_file(audio_path)
|
91 |
|
92 |
# Ses iyileştirme
|
93 |
if do_enhance:
|
94 |
audio = enhance_audio(audio)
|
95 |
+
audio.export(wav_path, format="wav")
|
96 |
|
97 |
# Konuşmacı ayrımı
|
98 |
if do_diarize:
|
99 |
+
diarization = diarize_speakers(wav_path)
|
100 |
else:
|
101 |
diarization = None
|
102 |
|
103 |
# Transkripsiyon
|
104 |
+
result = transcribe_audio(wav_path, diarization)
|
105 |
|
106 |
# Anonimleştirme
|
107 |
if do_anonymize:
|
108 |
result = anonymize_personal_info(result)
|
109 |
|
110 |
+
# JSON çıktısını hazırla
|
111 |
+
json_result = {
|
112 |
+
"transcript": result["text"],
|
113 |
+
"diarization": diarization,
|
114 |
+
"enhanced_audio": wav_path if do_enhance else None,
|
115 |
+
"anonymized": do_anonymize
|
116 |
+
}
|
117 |
+
|
118 |
+
return result["text"], json_result
|
119 |
|
120 |
except Exception as e:
|
121 |
error_msg = f"İşlem sırasında bir hata oluştu: {str(e)}"
|
122 |
print(error_msg)
|
123 |
+
return error_msg, {"error": str(e)}
|
124 |
|
125 |
# Ana arayüz
|
126 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"), css=css) as demo:
|