Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,11 @@ import wikipedia
|
|
| 7 |
import re
|
| 8 |
import time
|
| 9 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
nltk.download('maxent_ne_chunker') #Chunker
|
| 12 |
nltk.download('stopwords') #Stop Words List (Mainly Roman Languages)
|
|
@@ -288,6 +293,47 @@ def splittext(string):
|
|
| 288 |
linenumber += 1
|
| 289 |
return FinalOutput[2:]
|
| 290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
groupinput_text = gr.inputs.Textbox(lines=2, label="Enter a list of words")
|
| 292 |
groupoutput_text = gr.outputs.Textbox(label="Grouped words")
|
| 293 |
|
|
@@ -330,7 +376,7 @@ with gr.Blocks() as lliface:
|
|
| 330 |
<p>My One Word Theory = We only use more words than needed when we have to or are bored --> Headings exist because title is not sufficient, subheadings exist because headings are not sufficient, Book Text exists because subheadings are not sufficient</p>
|
| 331 |
<p>Big Picture = Expand the Heading and the subheadings and compare them to each other</p>
|
| 332 |
<p>Application of Knowledge = App Version of the text (eg. Jupyter Notebooks) is what you create and learn first</p>
|
| 333 |
-
""")
|
| 334 |
with gr.Tab("Beginner - Songs - Chorus"):
|
| 335 |
gr.HTML("Essentially if the sounds are repeated or long notes they are easy to remember")
|
| 336 |
gr.Interface(fn=TTSforListeningPractice, inputs="text", outputs="text", title="Placeholder - paste chorus here and use TTS or make notes to save here")
|
|
@@ -355,6 +401,8 @@ with gr.Blocks() as lliface:
|
|
| 355 |
with gr.Row():
|
| 356 |
MergeOutput = gr.TextArea(label="Output")
|
| 357 |
MergeButton.click(merge_lines, inputs=[RomanFile, W4WFile, FullMeanFile, MacaronicFile], outputs=[MergeOutput])
|
|
|
|
|
|
|
| 358 |
with gr.Tab("Sentence to Format"):
|
| 359 |
gr.Interface(fn=split_verbs_nouns , inputs="text", outputs=["text", "text"], title="Comprehension reading and Sentence Format Creator")
|
| 360 |
gr.Text("Text to Closed Class + Adjectives + Punctuation or Noun Verb + Punctuation ")
|
|
|
|
| 7 |
import re
|
| 8 |
import time
|
| 9 |
import random
|
| 10 |
+
import os
|
| 11 |
+
import zipfile
|
| 12 |
+
import gradio as gr
|
| 13 |
+
import ffmpeg
|
| 14 |
+
|
| 15 |
|
| 16 |
nltk.download('maxent_ne_chunker') #Chunker
|
| 17 |
nltk.download('stopwords') #Stop Words List (Mainly Roman Languages)
|
|
|
|
| 293 |
linenumber += 1
|
| 294 |
return FinalOutput[2:]
|
| 295 |
|
| 296 |
+
def VideotoSegment(video_file, subtitle_file):
|
| 297 |
+
# Read the subtitle file and extract the timings for each subtitle
|
| 298 |
+
timings = []
|
| 299 |
+
for line in subtitle_file:
|
| 300 |
+
if '-->' in line:
|
| 301 |
+
start, end = line.split('-->')
|
| 302 |
+
start_time = start.strip().replace(',', '.')
|
| 303 |
+
end_time = end.strip().replace(',', '.')
|
| 304 |
+
timings.append((start_time, end_time))
|
| 305 |
+
|
| 306 |
+
# Cut the video into segments based on the subtitle timings
|
| 307 |
+
video_segments = []
|
| 308 |
+
for i, (start_time, end_time) in enumerate(timings):
|
| 309 |
+
output_file = f'segment_{i}.mp4'
|
| 310 |
+
ffmpeg.input(video_file, ss=start_time, to=end_time).output(output_file, codec='copy').run()
|
| 311 |
+
video_segments.append(output_file)
|
| 312 |
+
|
| 313 |
+
# Convert each segment to an MP3 audio file using FFmpeg
|
| 314 |
+
audio_segments = []
|
| 315 |
+
for i in range(len(timings)):
|
| 316 |
+
output_file = f'segment_{i}.mp3'
|
| 317 |
+
ffmpeg.input(video_segments[i]).output(output_file, codec='libmp3lame', qscale='4').run()
|
| 318 |
+
audio_segments.append(output_file)
|
| 319 |
+
|
| 320 |
+
# Create a ZIP archive containing all of the segmented files
|
| 321 |
+
zip_file = zipfile.ZipFile('segmented_files.zip', 'w')
|
| 322 |
+
for segment in video_segments + audio_segments:
|
| 323 |
+
zip_file.write(segment)
|
| 324 |
+
os.remove(segment)
|
| 325 |
+
zip_file.close()
|
| 326 |
+
|
| 327 |
+
# Return the ZIP archive for download
|
| 328 |
+
return 'segmented_files.zip'
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
# Define the Gradio interface inputs and outputs for video split
|
| 332 |
+
spvvideo_file_input = gr.File(label='Video File')
|
| 333 |
+
spvsubtitle_file_input = gr.File(label='Subtitle File')
|
| 334 |
+
spvdownload_output = gr.File(label='Download Segmented Files')
|
| 335 |
+
|
| 336 |
+
|
| 337 |
groupinput_text = gr.inputs.Textbox(lines=2, label="Enter a list of words")
|
| 338 |
groupoutput_text = gr.outputs.Textbox(label="Grouped words")
|
| 339 |
|
|
|
|
| 376 |
<p>My One Word Theory = We only use more words than needed when we have to or are bored --> Headings exist because title is not sufficient, subheadings exist because headings are not sufficient, Book Text exists because subheadings are not sufficient</p>
|
| 377 |
<p>Big Picture = Expand the Heading and the subheadings and compare them to each other</p>
|
| 378 |
<p>Application of Knowledge = App Version of the text (eg. Jupyter Notebooks) is what you create and learn first</p>
|
| 379 |
+
""")
|
| 380 |
with gr.Tab("Beginner - Songs - Chorus"):
|
| 381 |
gr.HTML("Essentially if the sounds are repeated or long notes they are easy to remember")
|
| 382 |
gr.Interface(fn=TTSforListeningPractice, inputs="text", outputs="text", title="Placeholder - paste chorus here and use TTS or make notes to save here")
|
|
|
|
| 401 |
with gr.Row():
|
| 402 |
MergeOutput = gr.TextArea(label="Output")
|
| 403 |
MergeButton.click(merge_lines, inputs=[RomanFile, W4WFile, FullMeanFile, MacaronicFile], outputs=[MergeOutput])
|
| 404 |
+
with gr.Tab("Split video to segments"):
|
| 405 |
+
gr.Interface(VideotoSegment, inputs=[spvvideo_file_input, spvsubtitle_file_input], outputs=spvdownload_output)
|
| 406 |
with gr.Tab("Sentence to Format"):
|
| 407 |
gr.Interface(fn=split_verbs_nouns , inputs="text", outputs=["text", "text"], title="Comprehension reading and Sentence Format Creator")
|
| 408 |
gr.Text("Text to Closed Class + Adjectives + Punctuation or Noun Verb + Punctuation ")
|