Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,12 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
from videocr import save_subtitles_to_file
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Define OCR function
|
| 6 |
def run_video_ocr(input_video, output_file_name, language_code, use_gpu, start_time, end_time, confidence_threshold, similarity_threshold, frames_to_skip, crop_x, crop_y, crop_width, crop_height):
|
| 7 |
try:
|
|
@@ -62,13 +68,22 @@ def video_ocr_interface():
|
|
| 62 |
|
| 63 |
output_label = gr.Textbox(label="Status", interactive=False)
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# Define what happens when the button is clicked
|
| 66 |
submit_btn.click(
|
| 67 |
fn=run_video_ocr,
|
| 68 |
inputs=[input_video, output_file_name, language_code, use_gpu, start_time, end_time, confidence_threshold, similarity_threshold, frames_to_skip, crop_x, crop_y, crop_width, crop_height],
|
| 69 |
outputs=output_label
|
| 70 |
)
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
return demo
|
| 73 |
|
| 74 |
# Launch the Gradio interface
|
|
|
|
| 2 |
import os
|
| 3 |
from videocr import save_subtitles_to_file
|
| 4 |
|
| 5 |
+
# Function to list files in /data directory
|
| 6 |
+
def list_files():
|
| 7 |
+
files = os.listdir('/data')
|
| 8 |
+
file_paths = [f"/data/{file}" for file in files]
|
| 9 |
+
return file_paths
|
| 10 |
+
|
| 11 |
# Define OCR function
|
| 12 |
def run_video_ocr(input_video, output_file_name, language_code, use_gpu, start_time, end_time, confidence_threshold, similarity_threshold, frames_to_skip, crop_x, crop_y, crop_width, crop_height):
|
| 13 |
try:
|
|
|
|
| 68 |
|
| 69 |
output_label = gr.Textbox(label="Status", interactive=False)
|
| 70 |
|
| 71 |
+
# Define the file explorer component
|
| 72 |
+
file_list = gr.File(label="Download Extracted .srt Files", interactive=True)
|
| 73 |
+
|
| 74 |
+
# Refresh button to update the list of files
|
| 75 |
+
refresh_btn = gr.Button("Refresh File List")
|
| 76 |
+
|
| 77 |
# Define what happens when the button is clicked
|
| 78 |
submit_btn.click(
|
| 79 |
fn=run_video_ocr,
|
| 80 |
inputs=[input_video, output_file_name, language_code, use_gpu, start_time, end_time, confidence_threshold, similarity_threshold, frames_to_skip, crop_x, crop_y, crop_width, crop_height],
|
| 81 |
outputs=output_label
|
| 82 |
)
|
| 83 |
+
|
| 84 |
+
# Refresh the file explorer when the refresh button is clicked
|
| 85 |
+
refresh_btn.click(fn=list_files, inputs=[], outputs=file_list)
|
| 86 |
+
|
| 87 |
return demo
|
| 88 |
|
| 89 |
# Launch the Gradio interface
|