qqwjq1981 commited on
Commit
88cf326
·
verified ·
1 Parent(s): c7da96e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -27
app.py CHANGED
@@ -170,41 +170,30 @@ import json
170
 
171
  def update_translations(file, edited_table):
172
  """
173
- Update translations from the Gradio editable table and process the video.
174
-
175
- Parameters:
176
- file: Uploaded video file object.
177
- edited_table: Updated translations from the Gradio editable table (list of dictionaries).
178
-
179
- Returns:
180
- output_video_path: The path to the video with updated translations.
181
  """
182
  output_video_path = "output_video.mp4"
183
 
184
  try:
185
- # Ensure edited_table is in the expected format
186
- if not isinstance(edited_table, list):
187
- raise ValueError("Edited table must be a list of dictionaries.")
188
-
189
- # Validate and preprocess each entry in the edited_table
190
- for entry in edited_table:
191
- if not all(key in entry for key in ["start", "original", "translated", "end"]):
192
- raise ValueError("Each entry must contain 'start', 'original', 'translated', and 'end' keys.")
193
- if not isinstance(entry["start"], (float, int)):
194
- raise ValueError("'start' must be a number.")
195
- if not isinstance(entry["end"], (float, int)):
196
- raise ValueError("'end' must be a number.")
197
- if not isinstance(entry["original"], str) or not isinstance(entry["translated"], str):
198
- raise ValueError("'original' and 'translated' must be strings.")
199
-
200
- # Call the function to add subtitles to the video
201
- add_transcript_to_video(file.name, edited_table, output_video_path)
202
 
203
  except Exception as e:
204
  raise ValueError(f"Error updating translations: {e}")
205
 
206
- return output_video_path
207
-
208
  # Core functionalities
209
  def upload_and_manage(file, language):
210
  if file is None:
 
170
 
171
  def update_translations(file, edited_table):
172
  """
173
+ Update the translations based on user edits in the Gradio Dataframe.
 
 
 
 
 
 
 
174
  """
175
  output_video_path = "output_video.mp4"
176
 
177
  try:
178
+ # Convert the edited_table (list of lists) back to list of dictionaries
179
+ updated_translations = [
180
+ {
181
+ "start": row[0], # First column
182
+ "original": row[1], # Second column
183
+ "translated": row[2], # Third column
184
+ "end": row[3], # Fourth column
185
+ }
186
+ for row in edited_table
187
+ ]
188
+
189
+ # Call the function to process the video with updated translations
190
+ add_transcript_to_video(file.name, updated_translations, output_video_path)
191
+
192
+ return output_video_path
 
 
193
 
194
  except Exception as e:
195
  raise ValueError(f"Error updating translations: {e}")
196
 
 
 
197
  # Core functionalities
198
  def upload_and_manage(file, language):
199
  if file is None: