Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +26 -12
streamlit_app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
import tempfile
|
| 4 |
from faster_whisper import WhisperModel
|
|
@@ -41,24 +40,37 @@ def generate_fcpxml(segments, version):
|
|
| 41 |
f'<!DOCTYPE fcpxml>',
|
| 42 |
f'<fcpxml version="{version}">',
|
| 43 |
' <resources>',
|
| 44 |
-
' <format id="r1" name="
|
| 45 |
-
' <effect id="r2" name="
|
| 46 |
' </resources>',
|
| 47 |
' <library>',
|
| 48 |
-
' <event name="
|
| 49 |
' <project name="Subtitles">',
|
| 50 |
-
f' <sequence
|
| 51 |
-
' <spine>'
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
start = round(seg.start, 2)
|
| 54 |
duration = round(seg.end - seg.start, 2)
|
| 55 |
text = escape(seg.text.strip())
|
| 56 |
xml.append(
|
| 57 |
-
f'
|
| 58 |
-
f'
|
| 59 |
-
f'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
' </sequence>',
|
| 63 |
' </project>',
|
| 64 |
' </event>',
|
|
@@ -66,6 +78,7 @@ def generate_fcpxml(segments, version):
|
|
| 66 |
'</fcpxml>'])
|
| 67 |
return '\n'.join(xml)
|
| 68 |
|
|
|
|
| 69 |
with st.sidebar:
|
| 70 |
st.header("⚙️ Settings")
|
| 71 |
uploaded_file = st.file_uploader("Upload MP3 or WAV", type=["mp3", "wav"])
|
|
@@ -82,7 +95,7 @@ with st.sidebar:
|
|
| 82 |
}
|
| 83 |
language = st.selectbox("Language", list(language_map.keys()))
|
| 84 |
export_format = st.selectbox("Export Format", ["srt", "fcpxml"])
|
| 85 |
-
fcpxml_version = st.selectbox("FCPXML Version", ["1.13", "1.12", "1.11"], index=
|
| 86 |
|
| 87 |
if 'subtitle_data' not in st.session_state:
|
| 88 |
st.session_state.subtitle_data = ""
|
|
@@ -109,6 +122,7 @@ with st.sidebar:
|
|
| 109 |
|
| 110 |
st.session_state.generated = True
|
| 111 |
|
|
|
|
| 112 |
if st.session_state.generated and st.session_state.subtitle_data:
|
| 113 |
col1, col2 = st.columns([1, 6])
|
| 114 |
with col1:
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import tempfile
|
| 3 |
from faster_whisper import WhisperModel
|
|
|
|
| 40 |
f'<!DOCTYPE fcpxml>',
|
| 41 |
f'<fcpxml version="{version}">',
|
| 42 |
' <resources>',
|
| 43 |
+
' <format id="r1" name="FFVideoFormat1080p25" frameDuration="100/2500s" width="1920" height="1080" colorSpace="1-1-1 (Rec. 709)"/>',
|
| 44 |
+
' <effect id="r2" name="Custom" uid=".../Titles.localized/Build In:Out.localized/Custom.localized/Custom.moti"/>',
|
| 45 |
' </resources>',
|
| 46 |
' <library>',
|
| 47 |
+
' <event name="Subtitles">',
|
| 48 |
' <project name="Subtitles">',
|
| 49 |
+
f' <sequence format="r1" tcStart="0s" tcFormat="NDF">',
|
| 50 |
+
' <spine>',
|
| 51 |
+
f' <gap name="Gap" offset="0s" duration="{round(segments[-1].end, 2)}s">']
|
| 52 |
+
|
| 53 |
+
for i, seg in enumerate(segments):
|
| 54 |
start = round(seg.start, 2)
|
| 55 |
duration = round(seg.end - seg.start, 2)
|
| 56 |
text = escape(seg.text.strip())
|
| 57 |
xml.append(
|
| 58 |
+
f' <title name="Subtitle {i+1}" lane="1" offset="{start}s" ref="r2" duration="{duration}s">',
|
| 59 |
+
f' <param name="Position" key="9999/10199/10201/1/100/101" value="0 -415"/>',
|
| 60 |
+
f' <param name="Alignment" key="9999/10199/10201/2/354/1002961760/401" value="1 (Center)"/>',
|
| 61 |
+
f' <text>',
|
| 62 |
+
f' <text-style ref="ts{i+1}">{text}</text-style>',
|
| 63 |
+
f' </text>',
|
| 64 |
+
f' <text-style-def id="ts{i+1}">',
|
| 65 |
+
f' <text-style font="Arial" fontSize="60" fontColor="1 1 1 1" alignment="center" bold="1"',
|
| 66 |
+
f' strokeColor="0.3 0.3 0.3 1" strokeWidth="-1"',
|
| 67 |
+
f' shadowColor="0 0 0 0.75" shadowOffset="3 315" kerning="1.2"/>',
|
| 68 |
+
f' </text-style-def>',
|
| 69 |
+
f' </title>'
|
| 70 |
)
|
| 71 |
+
|
| 72 |
+
xml.extend([' </gap>',
|
| 73 |
+
' </spine>',
|
| 74 |
' </sequence>',
|
| 75 |
' </project>',
|
| 76 |
' </event>',
|
|
|
|
| 78 |
'</fcpxml>'])
|
| 79 |
return '\n'.join(xml)
|
| 80 |
|
| 81 |
+
# --- UI Sidebar ---
|
| 82 |
with st.sidebar:
|
| 83 |
st.header("⚙️ Settings")
|
| 84 |
uploaded_file = st.file_uploader("Upload MP3 or WAV", type=["mp3", "wav"])
|
|
|
|
| 95 |
}
|
| 96 |
language = st.selectbox("Language", list(language_map.keys()))
|
| 97 |
export_format = st.selectbox("Export Format", ["srt", "fcpxml"])
|
| 98 |
+
fcpxml_version = st.selectbox("FCPXML Version", ["1.13", "1.12", "1.11", "1.8"], index=3) if export_format == "fcpxml" else None
|
| 99 |
|
| 100 |
if 'subtitle_data' not in st.session_state:
|
| 101 |
st.session_state.subtitle_data = ""
|
|
|
|
| 122 |
|
| 123 |
st.session_state.generated = True
|
| 124 |
|
| 125 |
+
# --- Main UI Output ---
|
| 126 |
if st.session_state.generated and st.session_state.subtitle_data:
|
| 127 |
col1, col2 = st.columns([1, 6])
|
| 128 |
with col1:
|