Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
from tempfile import NamedTemporaryFile
|
| 4 |
|
| 5 |
def text_to_srt(text):
|
| 6 |
lines = text.split('\n')
|
|
@@ -16,28 +14,26 @@ def text_to_srt(text):
|
|
| 16 |
continue # Skip lines that don't match the expected format
|
| 17 |
return srt_content
|
| 18 |
|
| 19 |
-
def
|
| 20 |
-
srt_content = text_to_srt(
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
temp_file.write(srt_content)
|
| 26 |
-
temp_file.close()
|
| 27 |
-
return temp_file.name # Return the path for Gradio to handle
|
| 28 |
|
| 29 |
with gr.Blocks() as app:
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
file_path = convert_and_prepare_file(text_input)
|
| 37 |
-
if file_path:
|
| 38 |
-
return file_path, True # Return the path and make the file visible
|
| 39 |
-
return None, False # If no file was created, return None and keep the file component hidden
|
| 40 |
|
| 41 |
-
export_btn.click(fn=on_export_click, inputs=text_input, outputs=[output_file, output_file.visible])
|
| 42 |
-
|
| 43 |
-
app.launch(share=True)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def text_to_srt(text):
|
| 4 |
lines = text.split('\n')
|
|
|
|
| 14 |
continue # Skip lines that don't match the expected format
|
| 15 |
return srt_content
|
| 16 |
|
| 17 |
+
def text_to_srt_file(text):
|
| 18 |
+
srt_content = text_to_srt(text)
|
| 19 |
+
file_path = "output.srt"
|
| 20 |
+
with open(file_path, "w") as file:
|
| 21 |
+
file.write(srt_content)
|
| 22 |
+
return file_path
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
with gr.Blocks() as app:
|
| 25 |
+
gr.Markdown("### Text to SRT Converter")
|
| 26 |
+
text_input = gr.TextArea(label="Enter text in the specified format")
|
| 27 |
+
output = gr.TextArea(label="SRT Output", visible=False) # Hide the text area output
|
| 28 |
+
download_btn = gr.File(label="Download SRT", visible=False) # Add download button
|
| 29 |
+
|
| 30 |
+
def update_output(text):
|
| 31 |
+
srt_content = text_to_srt(text)
|
| 32 |
+
output.update(value=srt_content, visible=True)
|
| 33 |
+
srt_file_path = text_to_srt_file(text)
|
| 34 |
+
download_btn.update(value=srt_file_path, visible=True)
|
| 35 |
+
|
| 36 |
+
text_input.change(fn=update_output, inputs=text_input, outputs=[output, download_btn])
|
| 37 |
|
| 38 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
|
|
|
|
|
|
|
|