SoumyaJ commited on
Commit
1b8e760
·
verified ·
1 Parent(s): 654260d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -12,6 +12,9 @@ import langdetect
12
  import uuid
13
  from dotenv import load_dotenv
14
  import whisper
 
 
 
15
 
16
  load_dotenv()
17
 
@@ -44,13 +47,25 @@ def transcribe_audio(file_path):
44
  print("Video file detected. Extracting audio...")
45
  try:
46
  video = mp.VideoFileClip(file_path)
47
- temp_audio = generate_unique_filename(".mp3")
48
  video.audio.write_audiofile(temp_audio)
49
 
50
  print(f"temp_audio : {temp_audio}")
51
  model = whisper.load_model("base")
52
  print(f"transcription1")
53
- transcription = model.transcribe(temp_audio)
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  print(f"transcription {transcription}")
56
 
@@ -101,10 +116,10 @@ def generate_summary_stream(transcription):
101
  Please ensure that the summary captures the main points and key ideas of the transcription:
102
  {transcription[:300000]}..."""
103
 
104
- response, history = model.chat(tokenizer, prompt, history=[])
105
- print(f"Final summary generated: {response[:100]}...")
106
  print("Summary generation completed.")
107
- return response
108
 
109
  def process_uploaded_video(video_path):
110
  print(f"Processing uploaded video: {video_path}")
 
12
  import uuid
13
  from dotenv import load_dotenv
14
  import whisper
15
+ from pathlib import Path
16
+ import numpy as np
17
+ from scipy.io import wavfile
18
 
19
  load_dotenv()
20
 
 
47
  print("Video file detected. Extracting audio...")
48
  try:
49
  video = mp.VideoFileClip(file_path)
50
+ temp_audio = generate_unique_filename(".wav")
51
  video.audio.write_audiofile(temp_audio)
52
 
53
  print(f"temp_audio : {temp_audio}")
54
  model = whisper.load_model("base")
55
  print(f"transcription1")
56
+ p = Path(__file__).resolve().parent
57
+ final_path = p / temp_audio
58
+ print(final_path)
59
+ if os.access(str(final_path), os.R_OK):
60
+ print("File is readable.")
61
+ else:
62
+ print("File is not readable. Check permissions.")
63
+
64
+ sample_rate, audio_data = wavfile.read(str(final_path))
65
+
66
+
67
+ transcription = model.transcribe(audio_data, sample_rate=sample_rate)
68
+ #transcription = model.transcribe(str(final_path))
69
 
70
  print(f"transcription {transcription}")
71
 
 
116
  Please ensure that the summary captures the main points and key ideas of the transcription:
117
  {transcription[:300000]}..."""
118
 
119
+ #response, history = model.chat(tokenizer, prompt, history=[])
120
+ #print(f"Final summary generated: {response[:100]}...")
121
  print("Summary generation completed.")
122
+ return ""
123
 
124
  def process_uploaded_video(video_path):
125
  print(f"Processing uploaded video: {video_path}")