Spaces:
Running
Running
Update app.py
Browse files
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(
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
|
|
71 |
|
72 |
-
#
|
73 |
-
|
|
|
74 |
|
75 |
-
#
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
except Exception as e:
|
86 |
-
|
87 |
-
|
88 |
-
|
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:
|