sheikhed commited on
Commit
c953f53
·
verified ·
1 Parent(s): d52bea3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -47
app.py CHANGED
@@ -65,22 +65,20 @@ def save_uploaded_audio(audio_file, session_id):
65
  if audio_file is None:
66
  return None
67
 
68
- # Get the file extension from the original filename
69
- _, ext = os.path.splitext(audio_file.name)
70
- if not ext:
71
- ext = '.mp3' # Default extension if none is found
72
-
73
- # Save the uploaded audio file with session ID
74
- audio_file_path = f'temp_voice_{session_id}{ext}'
75
- with open(audio_file_path, 'wb') as f:
76
- if isinstance(audio_file, str): # If it's a file path
77
- with open(audio_file, 'rb') as source:
78
- f.write(source.read())
79
- else: # If it's a file object
80
- audio_file.seek(0)
81
- f.write(audio_file.read())
82
 
83
- return audio_file_path
84
 
85
  def upload_file(file_path):
86
  with open(file_path, 'rb') as file:
@@ -113,7 +111,7 @@ def lipsync_api_call(video_url, audio_url):
113
 
114
  def check_job_status(job_id):
115
  headers = {"x-api-key": B_KEY}
116
- max_attempts = 30 # Limit the number of attempts
117
 
118
  for _ in range(max_attempts):
119
  response = requests.get(f"{API_URL}/{job_id}", headers=headers)
@@ -224,42 +222,42 @@ def create_interface():
224
 
225
  with gr.Blocks() as app:
226
  gr.Markdown("# JSON Train")
227
- with gr.Row():
228
- with gr.Column():
229
- input_type = gr.Radio(
230
- choices=["text", "audio"],
231
- label="Input Type",
232
- value="text"
233
- )
234
-
235
- # Text-to-speech inputs
236
- with gr.Group() as text_inputs:
237
- voice_dropdown = gr.Dropdown(
238
- choices=[v[0] for v in voices],
239
- label="Select Voice",
240
- value=voices[0][0] if voices else None
241
- )
242
- text_input = gr.Textbox(label="Enter text", lines=3)
243
-
244
- # Audio upload input
245
- with gr.Group() as audio_inputs:
246
- audio_upload = gr.Audio(label="Upload Audio", type="filepath")
247
-
248
- model_dropdown = gr.Dropdown(
249
- choices=models,
250
- label="Select Video Model",
251
- value=models[0] if models else None
252
  )
253
- generate_btn = gr.Button("Generate Video")
 
 
 
 
254
 
255
- with gr.Column():
256
- video_output = gr.Video(label="Generated Video")
257
- status_output = gr.Textbox(label="Status", interactive=False)
 
 
 
 
 
 
 
258
 
259
  def toggle_inputs(input_type):
260
  return (
261
- gr.Group.update(visible=(input_type == "text")),
262
- gr.Group.update(visible=(input_type == "audio"))
263
  )
264
 
265
  input_type.change(
 
65
  if audio_file is None:
66
  return None
67
 
68
+ # If audio_file is already a path, just copy it
69
+ if isinstance(audio_file, str):
70
+ ext = os.path.splitext(audio_file)[1]
71
+ if not ext:
72
+ ext = '.mp3'
73
+ output_path = f'temp_voice_{session_id}{ext}'
74
+
75
+ # Copy the file to our temporary location
76
+ with open(audio_file, 'rb') as source:
77
+ with open(output_path, 'wb') as dest:
78
+ dest.write(source.read())
79
+ return output_path
 
 
80
 
81
+ return None
82
 
83
  def upload_file(file_path):
84
  with open(file_path, 'rb') as file:
 
111
 
112
  def check_job_status(job_id):
113
  headers = {"x-api-key": B_KEY}
114
+ max_attempts = 30
115
 
116
  for _ in range(max_attempts):
117
  response = requests.get(f"{API_URL}/{job_id}", headers=headers)
 
222
 
223
  with gr.Blocks() as app:
224
  gr.Markdown("# JSON Train")
225
+
226
+ input_type = gr.Radio(
227
+ choices=["text", "audio"],
228
+ label="Input Type",
229
+ value="text"
230
+ )
231
+
232
+ with gr.Column():
233
+ # Text-to-speech inputs
234
+ with gr.Column(visible=True) as text_inputs:
235
+ voice_dropdown = gr.Dropdown(
236
+ choices=[v[0] for v in voices],
237
+ label="Select Voice",
238
+ value=voices[0][0] if voices else None
 
 
 
 
 
 
 
 
 
 
 
239
  )
240
+ text_input = gr.Textbox(label="Enter text", lines=3)
241
+
242
+ # Audio upload input
243
+ with gr.Column(visible=False) as audio_inputs:
244
+ audio_upload = gr.Audio(label="Upload Audio", type="filepath")
245
 
246
+ model_dropdown = gr.Dropdown(
247
+ choices=models,
248
+ label="Select Video Model",
249
+ value=models[0] if models else None
250
+ )
251
+ generate_btn = gr.Button("Generate Video")
252
+
253
+ with gr.Column():
254
+ video_output = gr.Video(label="Generated Video")
255
+ status_output = gr.Textbox(label="Status", interactive=False)
256
 
257
  def toggle_inputs(input_type):
258
  return (
259
+ gr.Column.update(visible=(input_type == "text")),
260
+ gr.Column.update(visible=(input_type == "audio"))
261
  )
262
 
263
  input_type.change(