Adityadn commited on
Commit
9cd4fcb
·
verified ·
1 Parent(s): 412df1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -80,7 +80,7 @@ import ffmpeg
80
  # Function to convert video to audio using ffmpeg
81
  def convert_video_to_audio(video_path):
82
  try:
83
- output_path = f"flowly_ai_audio_converter{os.path.splittext(video_path)[0]}.mp3"
84
  ffmpeg.input(video_path).output(output_path).run()
85
  return output_path
86
  except Exception as e:
@@ -110,7 +110,7 @@ def recognize_audio(choice, url, file):
110
  file_extension = file.split('.')[-1].lower()
111
  audio_file_path = file
112
 
113
- video_formats = [data.upper() for data in (sorted(['3GP', 'ASF', 'AVI', 'DIVX', 'FLV', 'M2TS', 'M4V', 'MKV', 'MOV', 'MP4', 'MPEG', 'MPG', 'MTS', 'TS', 'VOB', 'WEBM', 'WMV', 'XVID'])) if data not in ['3GP', 'DIVX', 'XVID']]
114
 
115
  if file_extension in video_formats:
116
  # Convert video to audio file (mp3 format)
@@ -127,8 +127,16 @@ def recognize_audio(choice, url, file):
127
 
128
  # Parse the response into a structured format
129
  try:
 
 
 
 
130
  data = response.json()
131
 
 
 
 
 
132
  # Check if there's an error in the response
133
  if data.get("status") == "error":
134
  error_message = data.get("error", {}).get("error_message", "Unknown error.")
 
80
  # Function to convert video to audio using ffmpeg
81
  def convert_video_to_audio(video_path):
82
  try:
83
+ output_path = f"flowly_ai_audio_converter{os.path.splitext(video_path)[0]}.mp3"
84
  ffmpeg.input(video_path).output(output_path).run()
85
  return output_path
86
  except Exception as e:
 
110
  file_extension = file.split('.')[-1].lower()
111
  audio_file_path = file
112
 
113
+ video_formats = ['3gp', 'asf', 'avi', 'divx', 'flv', 'm2ts', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mts', 'ts', 'vob', 'webm', 'wmv', 'xvid']
114
 
115
  if file_extension in video_formats:
116
  # Convert video to audio file (mp3 format)
 
127
 
128
  # Parse the response into a structured format
129
  try:
130
+ if response.status_code != 200:
131
+ return f"Error: Received unexpected status code {response.status_code}"
132
+
133
+ # Try to parse the response as JSON
134
  data = response.json()
135
 
136
+ # Check if the response is valid
137
+ if not data:
138
+ return "Error: No data received from the API."
139
+
140
  # Check if there's an error in the response
141
  if data.get("status") == "error":
142
  error_message = data.get("error", {}).get("error_message", "Unknown error.")