Spaces:
Build error
Build error
Test 6
Browse files
app.py
CHANGED
|
@@ -9,6 +9,10 @@ import gradio as gr
|
|
| 9 |
import groq
|
| 10 |
from groq import Groq
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# setup groq
|
| 14 |
|
|
@@ -291,6 +295,28 @@ def json_to_srt(transcription_json):
|
|
| 291 |
|
| 292 |
return '\n'.join(srt_lines)
|
| 293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
|
| 295 |
def generate_subtitles(input_mode, input_file, link_input, prompt, language, auto_detect_language, model, include_video, font_selection, font_file, font_color, font_size, outline_thickness, outline_color):
|
| 296 |
if input_mode == "Upload Video/Audio File":
|
|
@@ -461,6 +487,13 @@ def generate_subtitles(input_mode, input_file, link_input, prompt, language, aut
|
|
| 461 |
except ValueError as e:
|
| 462 |
raise gr.Error(f"Error creating SRT file: {e}")
|
| 463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
theme = gr.themes.Soft(
|
| 466 |
primary_hue="sky",
|
|
|
|
| 9 |
import groq
|
| 10 |
from groq import Groq
|
| 11 |
|
| 12 |
+
import time
|
| 13 |
+
import psutil
|
| 14 |
+
import os
|
| 15 |
+
|
| 16 |
|
| 17 |
# setup groq
|
| 18 |
|
|
|
|
| 295 |
|
| 296 |
return '\n'.join(srt_lines)
|
| 297 |
|
| 298 |
+
def measure_response_time(func, *args, **kwargs):
|
| 299 |
+
start_time = time.time()
|
| 300 |
+
result = func(*args, **kwargs)
|
| 301 |
+
end_time = time.time()
|
| 302 |
+
response_time = end_time - start_time
|
| 303 |
+
return response_time, result
|
| 304 |
+
|
| 305 |
+
def measure_resource_usage(func, *args, **kwargs):
|
| 306 |
+
process = psutil.Process(os.getpid())
|
| 307 |
+
start_memory = process.memory_info().rss
|
| 308 |
+
start_cpu = process.cpu_percent(interval=None)
|
| 309 |
+
|
| 310 |
+
result = func(*args, **kwargs)
|
| 311 |
+
|
| 312 |
+
end_memory = process.memory_info().rss
|
| 313 |
+
end_cpu = process.cpu_percent(interval=None)
|
| 314 |
+
|
| 315 |
+
memory_usage = end_memory - start_memory
|
| 316 |
+
cpu_usage = end_cpu - start_cpu
|
| 317 |
+
|
| 318 |
+
return memory_usage, cpu_usage, result
|
| 319 |
+
|
| 320 |
|
| 321 |
def generate_subtitles(input_mode, input_file, link_input, prompt, language, auto_detect_language, model, include_video, font_selection, font_file, font_color, font_size, outline_thickness, outline_color):
|
| 322 |
if input_mode == "Upload Video/Audio File":
|
|
|
|
| 487 |
except ValueError as e:
|
| 488 |
raise gr.Error(f"Error creating SRT file: {e}")
|
| 489 |
|
| 490 |
+
response_time, result = measure_response_time(generate_subtitles, input_mode, input_file, link_input, prompt, language, auto_detect_language, model, include_video, font_selection, font_file, font_color, font_size, outline_thickness, outline_color)
|
| 491 |
+
memory_usage, cpu_usage, result = measure_resource_usage(generate_subtitles, input_mode, input_file, link_input, prompt, language, auto_detect_language, model, include_video, font_selection, font_file, font_color, font_size, outline_thickness, outline_color)
|
| 492 |
+
|
| 493 |
+
print(f"Response Time: {response_time} seconds")
|
| 494 |
+
print(f"Memory Usage: {memory_usage} bytes")
|
| 495 |
+
print(f"CPU Usage: {cpu_usage} %")
|
| 496 |
+
|
| 497 |
|
| 498 |
theme = gr.themes.Soft(
|
| 499 |
primary_hue="sky",
|