Spaces:
Sleeping
Sleeping
Changes in transcribe_audio, made directly using mp4
Browse files
app.py
CHANGED
|
@@ -75,30 +75,45 @@ def process_video():
|
|
| 75 |
os.remove(temp_video_file.name)
|
| 76 |
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def transcribe_audio(video_path):
|
| 79 |
"""
|
| 80 |
-
|
| 81 |
"""
|
| 82 |
try:
|
| 83 |
-
#
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
"ffmpeg",
|
| 87 |
-
"-i", video_path,
|
| 88 |
-
"-q:a", "0",
|
| 89 |
-
"-map", "a",
|
| 90 |
-
audio_path
|
| 91 |
-
]
|
| 92 |
-
subprocess.run(command, check=True)
|
| 93 |
-
print(f"Audio extracted to: {audio_path}")
|
| 94 |
-
|
| 95 |
-
# Transcribe audio using Whisper AI
|
| 96 |
-
print("Transcribing audio...")
|
| 97 |
-
result = whisper_model.transcribe(audio_path)
|
| 98 |
-
|
| 99 |
-
# Clean up audio file after transcription
|
| 100 |
-
if os.path.exists(audio_path):
|
| 101 |
-
os.remove(audio_path)
|
| 102 |
|
| 103 |
return result.get("text", "").strip()
|
| 104 |
|
|
@@ -107,6 +122,7 @@ def transcribe_audio(video_path):
|
|
| 107 |
return None
|
| 108 |
|
| 109 |
|
|
|
|
| 110 |
def query_gemini_api(transcription):
|
| 111 |
"""
|
| 112 |
Send transcription text to Gemini API and fetch structured recipe information.
|
|
|
|
| 75 |
os.remove(temp_video_file.name)
|
| 76 |
|
| 77 |
|
| 78 |
+
# def transcribe_audio(video_path):
|
| 79 |
+
# """
|
| 80 |
+
# Extract audio from video file and transcribe using Whisper AI.
|
| 81 |
+
# """
|
| 82 |
+
# try:
|
| 83 |
+
# # Extract audio using ffmpeg
|
| 84 |
+
# audio_path = video_path.replace(".mp4", ".wav")
|
| 85 |
+
# command = [
|
| 86 |
+
# "ffmpeg",
|
| 87 |
+
# "-i", video_path,
|
| 88 |
+
# "-q:a", "0",
|
| 89 |
+
# "-map", "a",
|
| 90 |
+
# audio_path
|
| 91 |
+
# ]
|
| 92 |
+
# subprocess.run(command, check=True)
|
| 93 |
+
# print(f"Audio extracted to: {audio_path}")
|
| 94 |
+
|
| 95 |
+
# # Transcribe audio using Whisper AI
|
| 96 |
+
# print("Transcribing audio...")
|
| 97 |
+
# result = whisper_model.transcribe(audio_path)
|
| 98 |
+
|
| 99 |
+
# # Clean up audio file after transcription
|
| 100 |
+
# if os.path.exists(audio_path):
|
| 101 |
+
# os.remove(audio_path)
|
| 102 |
+
|
| 103 |
+
# return result.get("text", "").strip()
|
| 104 |
+
|
| 105 |
+
# except Exception as e:
|
| 106 |
+
# print(f"Error in transcription: {e}")
|
| 107 |
+
# return None
|
| 108 |
+
|
| 109 |
def transcribe_audio(video_path):
|
| 110 |
"""
|
| 111 |
+
Transcribe audio directly from a video file using Whisper AI.
|
| 112 |
"""
|
| 113 |
try:
|
| 114 |
+
# Transcribe audio from video directly using Whisper AI
|
| 115 |
+
print(f"Transcribing video: {video_path}")
|
| 116 |
+
result = whisper_model.transcribe(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
return result.get("text", "").strip()
|
| 119 |
|
|
|
|
| 122 |
return None
|
| 123 |
|
| 124 |
|
| 125 |
+
|
| 126 |
def query_gemini_api(transcription):
|
| 127 |
"""
|
| 128 |
Send transcription text to Gemini API and fetch structured recipe information.
|