Update app.py
Browse files
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 |
-
#
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
with open(
|
78 |
-
|
79 |
-
|
80 |
-
audio_file.seek(0)
|
81 |
-
f.write(audio_file.read())
|
82 |
|
83 |
-
return
|
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
|
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 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
254 |
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
|
259 |
def toggle_inputs(input_type):
|
260 |
return (
|
261 |
-
gr.
|
262 |
-
gr.
|
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(
|