Cryptic commited on
Commit
6440aaf
·
1 Parent(s): 10cfa3b
Files changed (1) hide show
  1. app.py +22 -24
app.py CHANGED
@@ -30,35 +30,33 @@ def load_and_convert_audio(audio_path):
30
  def process_audio(audio_path):
31
  """Process audio file and return transcription and summary"""
32
  results = {}
33
- temp_wav_path = load_and_convert_audio(audio_path)
34
-
35
- # Transcription
36
- transcription = models['transcriber'](temp_wav_path, return_timestamps=True)
37
- if isinstance(transcription, dict):
38
- results['transcription'] = transcription['text']
39
- else:
40
- results['transcription'] = ' '.join([chunk['text'] for chunk in transcription])
41
-
42
- # Summarization
43
- text = results['transcription']
44
- words = text.split()
45
- chunk_size = 1000
46
- chunks = [' '.join(words[i:i + chunk_size]) for i in range(0, len(words), chunk_size)]
47
 
48
- summaries = []
49
- for chunk in chunks:
50
- summary = models['summarizer'](chunk, max_length=200, min_length=50, truncation=True)
51
- summaries.append(summary[0]['summary_text'])
52
-
53
- combined_summary = ' '.join(summaries)
54
- results['summary'] = combined_summary
 
 
 
 
 
55
 
56
- # Clean up temporary WAV file
57
- if os.path.exists(temp_wav_path):
58
- os.unlink(temp_wav_path)
 
 
 
 
 
 
59
 
60
  return results
61
 
 
62
  @app.route('/process-audio', methods=['POST'])
63
  def process_audio_endpoint():
64
  """API endpoint to process audio file"""
 
30
  def process_audio(audio_path):
31
  """Process audio file and return transcription and summary"""
32
  results = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ try:
35
+ temp_wav_path = load_and_convert_audio(audio_path)
36
+
37
+ # Transcription
38
+ transcription = models['transcriber'](temp_wav_path, return_timestamps=True)
39
+ results['transcription'] = transcription['text'] if isinstance(transcription, dict) else ' '.join([chunk['text'] for chunk in transcription])
40
+
41
+ # Summarization
42
+ text = results['transcription']
43
+ words = text.split()
44
+ chunk_size = 1000
45
+ chunks = [' '.join(words[i:i + chunk_size]) for i in range(0, len(words), chunk_size)]
46
 
47
+ summaries = [models['summarizer'](chunk, max_length=200, min_length=50, truncation=True)[0]['summary_text'] for chunk in chunks]
48
+ results['summary'] = ' '.join(summaries)
49
+
50
+ except Exception as e:
51
+ return {'error': str(e)}, 500 # Return error message if something goes wrong
52
+
53
+ finally:
54
+ if os.path.exists(temp_wav_path):
55
+ os.unlink(temp_wav_path)
56
 
57
  return results
58
 
59
+
60
  @app.route('/process-audio', methods=['POST'])
61
  def process_audio_endpoint():
62
  """API endpoint to process audio file"""