Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ from nltk.tokenize import sent_tokenize
|
|
| 18 |
import logging
|
| 19 |
from textblob import TextBlob
|
| 20 |
import whisper
|
| 21 |
-
|
| 22 |
import sqlite3
|
| 23 |
|
| 24 |
# Define the passcode
|
|
@@ -224,35 +224,31 @@ def upload_and_manage(file, language):
|
|
| 224 |
|
| 225 |
return translated_json, editable_table, output_video_path
|
| 226 |
|
| 227 |
-
#
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
|
|
|
| 233 |
|
| 234 |
-
#
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
# for metric, value in data.items():
|
| 238 |
-
# dashboard += f" {metric}: {value}\n"
|
| 239 |
-
# return dashboard
|
| 240 |
|
| 241 |
# Gradio Interface with Tabs
|
| 242 |
def build_interface():
|
| 243 |
with gr.Blocks() as demo:
|
| 244 |
-
# with gr.Tab("Content Management"):
|
| 245 |
gr.Markdown("## Video Localization")
|
| 246 |
with gr.Row():
|
| 247 |
with gr.Column(scale=4):
|
| 248 |
file_input = gr.File(label="Upload Video/Audio File")
|
| 249 |
-
# platform_input = gr.Dropdown(["YouTube", "Instagram"], label="Select Platform")
|
| 250 |
language_input = gr.Dropdown(["en", "es", "fr", "zh"], label="Select Language") # Language codes
|
| 251 |
submit_button = gr.Button("Post and Process")
|
| 252 |
editable_translations = gr.State(value=[])
|
| 253 |
|
| 254 |
with gr.Column(scale=8):
|
| 255 |
-
|
| 256 |
gr.Markdown("## Edit Translations")
|
| 257 |
|
| 258 |
# Editable JSON Data
|
|
@@ -267,6 +263,7 @@ def build_interface():
|
|
| 267 |
)
|
| 268 |
save_changes_button = gr.Button("Save Changes")
|
| 269 |
processed_video_output = gr.File(label="Download Processed Video", interactive=True) # Download button
|
|
|
|
| 270 |
|
| 271 |
with gr.Column(scale=1):
|
| 272 |
gr.Markdown("**Feedback**")
|
|
@@ -275,7 +272,7 @@ def build_interface():
|
|
| 275 |
label=None,
|
| 276 |
lines=3,
|
| 277 |
)
|
| 278 |
-
feedback_btn = gr.Button("Submit
|
| 279 |
response_message = gr.Textbox(label=None, lines=1, interactive=False)
|
| 280 |
db_download = gr.File(label="Download Database File", visible=False)
|
| 281 |
|
|
@@ -284,18 +281,18 @@ def build_interface():
|
|
| 284 |
message, file_path = handle_feedback(feedback)
|
| 285 |
if file_path:
|
| 286 |
return message, gr.update(value=file_path, visible=True)
|
| 287 |
-
return message, gr.update(visible=False)
|
| 288 |
|
| 289 |
save_changes_button.click(
|
| 290 |
-
|
| 291 |
inputs=[file_input, editable_table],
|
| 292 |
-
outputs=[processed_video_output]
|
| 293 |
)
|
| 294 |
|
| 295 |
submit_button.click(
|
| 296 |
-
|
| 297 |
inputs=[file_input, language_input],
|
| 298 |
-
outputs=[editable_translations, editable_table, processed_video_output]
|
| 299 |
)
|
| 300 |
|
| 301 |
# Connect submit button to save_feedback_db function
|
|
@@ -305,13 +302,6 @@ def build_interface():
|
|
| 305 |
outputs=[response_message, db_download]
|
| 306 |
)
|
| 307 |
|
| 308 |
-
# with gr.Tab("Analytics Dashboard"):
|
| 309 |
-
# gr.Markdown("## Content Performance Analytics")
|
| 310 |
-
# analytics_output = gr.Textbox(label="Dashboard", interactive=False)
|
| 311 |
-
# generate_dashboard_button = gr.Button("Generate Dashboard")
|
| 312 |
-
|
| 313 |
-
# generate_dashboard_button.click(generate_dashboard, outputs=[analytics_output])
|
| 314 |
-
|
| 315 |
return demo
|
| 316 |
|
| 317 |
# Launch the Gradio interface
|
|
|
|
| 18 |
import logging
|
| 19 |
from textblob import TextBlob
|
| 20 |
import whisper
|
| 21 |
+
import time
|
| 22 |
import sqlite3
|
| 23 |
|
| 24 |
# Define the passcode
|
|
|
|
| 224 |
|
| 225 |
return translated_json, editable_table, output_video_path
|
| 226 |
|
| 227 |
+
# Wrapper to measure time elapsed
|
| 228 |
+
def time_execution(func):
|
| 229 |
+
def wrapper(*args, **kwargs):
|
| 230 |
+
start_time = time.time()
|
| 231 |
+
result = func(*args, **kwargs)
|
| 232 |
+
elapsed_time = time.time() - start_time
|
| 233 |
+
return result, f"Time elapsed: {elapsed_time:.2f} seconds"
|
| 234 |
+
return wrapper
|
| 235 |
|
| 236 |
+
# Wrap the functions with the timer
|
| 237 |
+
timed_upload_and_manage = time_execution(upload_and_manage)
|
| 238 |
+
timed_update_translations = time_execution(update_translations)
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
# Gradio Interface with Tabs
|
| 241 |
def build_interface():
|
| 242 |
with gr.Blocks() as demo:
|
|
|
|
| 243 |
gr.Markdown("## Video Localization")
|
| 244 |
with gr.Row():
|
| 245 |
with gr.Column(scale=4):
|
| 246 |
file_input = gr.File(label="Upload Video/Audio File")
|
|
|
|
| 247 |
language_input = gr.Dropdown(["en", "es", "fr", "zh"], label="Select Language") # Language codes
|
| 248 |
submit_button = gr.Button("Post and Process")
|
| 249 |
editable_translations = gr.State(value=[])
|
| 250 |
|
| 251 |
with gr.Column(scale=8):
|
|
|
|
| 252 |
gr.Markdown("## Edit Translations")
|
| 253 |
|
| 254 |
# Editable JSON Data
|
|
|
|
| 263 |
)
|
| 264 |
save_changes_button = gr.Button("Save Changes")
|
| 265 |
processed_video_output = gr.File(label="Download Processed Video", interactive=True) # Download button
|
| 266 |
+
elapsed_time_display = gr.Textbox(label="Elapsed Time", lines=1, interactive=False)
|
| 267 |
|
| 268 |
with gr.Column(scale=1):
|
| 269 |
gr.Markdown("**Feedback**")
|
|
|
|
| 272 |
label=None,
|
| 273 |
lines=3,
|
| 274 |
)
|
| 275 |
+
feedback_btn = gr.Button("Submit Feedback")
|
| 276 |
response_message = gr.Textbox(label=None, lines=1, interactive=False)
|
| 277 |
db_download = gr.File(label="Download Database File", visible=False)
|
| 278 |
|
|
|
|
| 281 |
message, file_path = handle_feedback(feedback)
|
| 282 |
if file_path:
|
| 283 |
return message, gr.update(value=file_path, visible=True)
|
| 284 |
+
return message, gr.update(visible=False)
|
| 285 |
|
| 286 |
save_changes_button.click(
|
| 287 |
+
timed_update_translations,
|
| 288 |
inputs=[file_input, editable_table],
|
| 289 |
+
outputs=[processed_video_output, elapsed_time_display]
|
| 290 |
)
|
| 291 |
|
| 292 |
submit_button.click(
|
| 293 |
+
timed_upload_and_manage,
|
| 294 |
inputs=[file_input, language_input],
|
| 295 |
+
outputs=[editable_translations, editable_table, processed_video_output, elapsed_time_display]
|
| 296 |
)
|
| 297 |
|
| 298 |
# Connect submit button to save_feedback_db function
|
|
|
|
| 302 |
outputs=[response_message, db_download]
|
| 303 |
)
|
| 304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
return demo
|
| 306 |
|
| 307 |
# Launch the Gradio interface
|