Marek4321 commited on
Commit
d406562
·
verified ·
1 Parent(s): a451ea6

Update transcription.py

Browse files
Files changed (1) hide show
  1. transcription.py +7 -39
transcription.py CHANGED
@@ -1,9 +1,9 @@
1
- # transcription.py - Poprawiony moduł transkrypcji
2
 
3
  import os
4
  import time
5
  import streamlit as st
6
- from typing import List, Dict, Optional, Union
7
  from pathlib import Path
8
 
9
  try:
@@ -142,8 +142,7 @@ class AudioTranscriber:
142
  params = {
143
  'model': MODEL_SETTINGS['whisper']['model'],
144
  'file': audio_file,
145
- 'temperature': MODEL_SETTINGS['whisper']['temperature'],
146
- 'response_format': 'text' # Zwróć tylko tekst
147
  }
148
 
149
  # Dodaj język tylko jeśli nie jest auto
@@ -154,7 +153,7 @@ class AudioTranscriber:
154
  transcript = self.client.audio.transcriptions.create(**params)
155
 
156
  # Sprawdź czy otrzymaliśmy wynik
157
- if not transcript or len(transcript.strip()) == 0:
158
  raise Exception("Pusty wynik transkrypcji")
159
 
160
  # Estymacja kosztu (Whisper API: $0.006 per minute)
@@ -163,10 +162,10 @@ class AudioTranscriber:
163
  self.transcription_stats['total_duration'] += estimated_duration
164
  self.transcription_stats['total_cost_estimate'] += estimated_cost
165
 
166
- st.success(f"✅ Transkrypcja otrzymana ({len(transcript.split())} słów)")
167
 
168
  # Oczyść i zwróć transkrypcję
169
- return self.clean_transcription(transcript)
170
 
171
  except Exception as e:
172
  st.error(f"❌ Błąd Whisper API: {str(e)}")
@@ -353,35 +352,4 @@ def get_file_duration_estimate(file_path: str) -> float:
353
  # Test modułu
354
  if __name__ == "__main__":
355
  print("🧪 Test AudioTranscriber")
356
-
357
- # Test bez prawdziwego API key
358
- try:
359
- transcriber = AudioTranscriber("test-key")
360
- print("✅ AudioTranscriber zainicjalizowany")
361
-
362
- # Test rozpoznania typu wywiadu
363
- test_fgi = """
364
- Moderator: Dzień dobry wszystkim. Co wszyscy myślicie o tym produkcie?
365
- Uczestnik 1: Ja uważam, że...
366
- Uczestnik 2: Ale czy zgadzacie się, że...
367
- Moderator: A co sądzicie o tym?
368
- """
369
-
370
- test_idi = """
371
- Interviewer: Opowiedz mi o swoich doświadczeniach z tym produktem.
372
- Respondent: Moje doświadczenia są bardzo pozytywne...
373
- Interviewer: A jak się czujesz gdy używasz tego produktu?
374
- """
375
-
376
- print(f"Test FGI: {transcriber.detect_interview_type(test_fgi)}")
377
- print(f"Test IDI: {transcriber.detect_interview_type(test_idi)}")
378
-
379
- # Test walidacji pliku
380
- test_file = "test.mp3"
381
- result, message = validate_audio_file(test_file)
382
- print(f"Test walidacji: {result} - {message}")
383
-
384
- except Exception as e:
385
- print(f"❌ Błąd testu: {e}")
386
-
387
- print("✅ Test zakończony")
 
1
+ # transcription.py - Szybka poprawka importów
2
 
3
  import os
4
  import time
5
  import streamlit as st
6
+ from typing import List, Dict, Optional, Union, Tuple # Dodano Tuple
7
  from pathlib import Path
8
 
9
  try:
 
142
  params = {
143
  'model': MODEL_SETTINGS['whisper']['model'],
144
  'file': audio_file,
145
+ 'temperature': MODEL_SETTINGS['whisper']['temperature']
 
146
  }
147
 
148
  # Dodaj język tylko jeśli nie jest auto
 
153
  transcript = self.client.audio.transcriptions.create(**params)
154
 
155
  # Sprawdź czy otrzymaliśmy wynik
156
+ if not transcript or not hasattr(transcript, 'text') or len(transcript.text.strip()) == 0:
157
  raise Exception("Pusty wynik transkrypcji")
158
 
159
  # Estymacja kosztu (Whisper API: $0.006 per minute)
 
162
  self.transcription_stats['total_duration'] += estimated_duration
163
  self.transcription_stats['total_cost_estimate'] += estimated_cost
164
 
165
+ st.success(f"✅ Transkrypcja otrzymana ({len(transcript.text.split())} słów)")
166
 
167
  # Oczyść i zwróć transkrypcję
168
+ return self.clean_transcription(transcript.text)
169
 
170
  except Exception as e:
171
  st.error(f"❌ Błąd Whisper API: {str(e)}")
 
352
  # Test modułu
353
  if __name__ == "__main__":
354
  print("🧪 Test AudioTranscriber")
355
+ print("✅ Import OK - wszystkie typy dostępne")