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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Q-Sheet Generator — Film & Short Film
|
| 3 |
+
Parses Pro Tools session text exports and builds a clean sound cue sheet.
|
| 4 |
+
Deployable on HuggingFace Spaces (Gradio SDK).
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import re
|
| 10 |
+
import os
|
| 11 |
+
from datetime import datetime
|
| 12 |
+
|
| 13 |
+
# ── Constants ─────────────────────────────────────────────────────────────────
|
| 14 |
+
|
| 15 |
+
COLUMNS = ["#", "Clip Name", "Track", "Channel", "Start", "End", "Duration", "State"]
|
| 16 |
+
|
| 17 |
+
SKIP_PATTERNS = re.compile(
|
| 18 |
+
r"^\s*\((fade in|fade out|cross fade|fade)\)\s*$",
|
| 19 |
+
re.IGNORECASE,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# ── Helpers ───────────────────────────────────────────────────────────────────
|
| 23 |
+
|
| 24 |
+
def empty_df() -> pd.DataFrame:
|
| 25 |
+
return pd.DataFrame(columns=COLUMNS)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def strip_channel_suffix(name: str) -> str:
|
| 29 |
+
"""Remove trailing .L / .R from clip names for cleaner display."""
|
| 30 |
+
return re.sub(r"\.[LR]$", "", name.strip())
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# ── Parser ────────────────────────────────────────────────────────────────────
|
| 34 |
+
|
| 35 |
+
def parse_protools_export(text: str):
|
| 36 |
+
lines = text.splitlines()
|
| 37 |
+
|
| 38 |
+
session_info = {}
|
| 39 |
+
meta_keys = ["SESSION NAME", "SAMPLE RATE", "BIT DEPTH",
|
| 40 |
+
"SESSION START TIMECODE", "TIMECODE FORMAT",
|
| 41 |
+
"# OF AUDIO TRACKS", "# OF AUDIO CLIPS", "# OF AUDIO FILES"]
|
| 42 |
+
for line in lines:
|
| 43 |
+
for key in meta_keys:
|
| 44 |
+
if line.upper().startswith(key + ":"):
|
| 45 |
+
session_info[key] = line.split(":", 1)[1].strip()
|
| 46 |
+
|
| 47 |
+
rows = []
|
| 48 |
+
current_track = None
|
| 49 |
+
cue_number = 0
|
| 50 |
+
|
| 51 |
+
for line in lines:
|
| 52 |
+
if line.strip().upper().startswith("TRACK NAME:"):
|
| 53 |
+
current_track = line.split(":", 1)[1].strip()
|
| 54 |
+
continue
|
| 55 |
+
|
| 56 |
+
parts = line.split("\t")
|
| 57 |
+
if len(parts) >= 7 and parts[0].strip().isdigit():
|
| 58 |
+
channel = parts[0].strip()
|
| 59 |
+
clip_name = parts[2].strip()
|
| 60 |
+
start = parts[3].strip()
|
| 61 |
+
end = parts[4].strip()
|
| 62 |
+
duration = parts[5].strip()
|
| 63 |
+
state = parts[6].strip()
|
| 64 |
+
|
| 65 |
+
if SKIP_PATTERNS.match(clip_name):
|
| 66 |
+
continue
|
| 67 |
+
|
| 68 |
+
cue_number += 1
|
| 69 |
+
rows.append({
|
| 70 |
+
"#": cue_number,
|
| 71 |
+
"Clip Name": strip_channel_suffix(clip_name),
|
| 72 |
+
"Track": current_track or "",
|
| 73 |
+
"Channel": channel,
|
| 74 |
+
"Start": start,
|
| 75 |
+
"End": end,
|
| 76 |
+
"Duration": duration,
|
| 77 |
+
"State": state,
|
| 78 |
+
})
|
| 79 |
+
|
| 80 |
+
df = pd.DataFrame(rows, columns=COLUMNS) if rows else empty_df()
|
| 81 |
+
return session_info, df
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
# ── Handlers ──────────────────────────────────────────────────────────────────
|
| 85 |
+
|
| 86 |
+
def import_protools_file(file, include_muted):
|
| 87 |
+
if file is None:
|
| 88 |
+
return empty_df(), {}, gr.update(value="No file selected.", visible=True), ""
|
| 89 |
+
try:
|
| 90 |
+
for enc in ("utf-8", "utf-16", "latin-1", "cp1252"):
|
| 91 |
+
try:
|
| 92 |
+
with open(file.name, encoding=enc) as f:
|
| 93 |
+
text = f.read()
|
| 94 |
+
break
|
| 95 |
+
except (UnicodeDecodeError, UnicodeError):
|
| 96 |
+
continue
|
| 97 |
+
else:
|
| 98 |
+
return empty_df(), {}, gr.update(value="Could not decode file.", visible=True), ""
|
| 99 |
+
|
| 100 |
+
session_info, df = parse_protools_export(text)
|
| 101 |
+
|
| 102 |
+
if not include_muted:
|
| 103 |
+
df = df[df["State"].str.lower() != "muted"].reset_index(drop=True)
|
| 104 |
+
df["#"] = range(1, len(df) + 1)
|
| 105 |
+
|
| 106 |
+
summary = "\n".join(f"{k}: {v}" for k, v in session_info.items())
|
| 107 |
+
name = session_info.get("SESSION NAME", "Unknown")
|
| 108 |
+
msg = f"Imported {len(df)} cues from \"{name}\""
|
| 109 |
+
return df, session_info, gr.update(value=msg, visible=True), summary
|
| 110 |
+
|
| 111 |
+
except Exception as ex:
|
| 112 |
+
return empty_df(), {}, gr.update(value=f"Parse error: {ex}", visible=True), ""
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def import_csv_file(file, current_data):
|
| 116 |
+
if file is None:
|
| 117 |
+
return current_data, gr.update(value="No file selected.", visible=True)
|
| 118 |
+
try:
|
| 119 |
+
df = pd.read_csv(file.name)
|
| 120 |
+
df.columns = [c.strip() for c in df.columns]
|
| 121 |
+
for col in COLUMNS:
|
| 122 |
+
if col not in df.columns:
|
| 123 |
+
df[col] = ""
|
| 124 |
+
df = df[COLUMNS].reset_index(drop=True)
|
| 125 |
+
df["#"] = range(1, len(df) + 1)
|
| 126 |
+
return df, gr.update(value=f"Imported {len(df)} rows.", visible=True)
|
| 127 |
+
except Exception as ex:
|
| 128 |
+
return current_data, gr.update(value=f"Import error: {ex}", visible=True)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def add_entry(clip_name, track, start, end, duration, state, current_data):
|
| 132 |
+
if not clip_name.strip():
|
| 133 |
+
return current_data, gr.update(value="Clip name is required.", visible=True)
|
| 134 |
+
df = current_data if current_data is not None and len(current_data) > 0 else empty_df()
|
| 135 |
+
row = {"#": len(df)+1, "Clip Name": clip_name.strip(), "Track": track.strip(),
|
| 136 |
+
"Channel": "1", "Start": start.strip(), "End": end.strip(),
|
| 137 |
+
"Duration": duration.strip(), "State": state}
|
| 138 |
+
df = pd.concat([df, pd.DataFrame([row])], ignore_index=True)
|
| 139 |
+
return df, gr.update(value="Entry added.", visible=True)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def delete_last(current_data):
|
| 143 |
+
df = current_data if current_data is not None and len(current_data) > 0 else empty_df()
|
| 144 |
+
if len(df) == 0:
|
| 145 |
+
return df, gr.update(value="Nothing to delete.", visible=True)
|
| 146 |
+
df = df.iloc[:-1].reset_index(drop=True)
|
| 147 |
+
df["#"] = range(1, len(df) + 1)
|
| 148 |
+
return df, gr.update(value="Last entry deleted.", visible=True)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def clear_all():
|
| 152 |
+
return empty_df(), gr.update(value="Sheet cleared.", visible=True)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def _safe(s): return "".join(c if c.isalnum() or c in "-_ " else "_" for c in (s.strip() or "qsheet"))
|
| 156 |
+
|
| 157 |
+
def export_csv(project, current_data):
|
| 158 |
+
df = current_data if current_data is not None and len(current_data) > 0 else empty_df()
|
| 159 |
+
path = f"/tmp/{_safe(project)}_{datetime.now().strftime('%Y%m%d')}.csv"
|
| 160 |
+
df.to_csv(path, index=False)
|
| 161 |
+
return path, gr.update(value=f"CSV ready: {os.path.basename(path)}", visible=True)
|
| 162 |
+
|
| 163 |
+
def export_xlsx(project, current_data):
|
| 164 |
+
df = current_data if current_data is not None and len(current_data) > 0 else empty_df()
|
| 165 |
+
path = f"/tmp/{_safe(project)}_{datetime.now().strftime('%Y%m%d')}.xlsx"
|
| 166 |
+
with pd.ExcelWriter(path, engine="openpyxl") as writer:
|
| 167 |
+
df.to_excel(writer, index=False, sheet_name="Q-Sheet")
|
| 168 |
+
ws = writer.sheets["Q-Sheet"]
|
| 169 |
+
for col in ws.columns:
|
| 170 |
+
ws.column_dimensions[col[0].column_letter].width = max(len(str(c.value or "")) for c in col) + 4
|
| 171 |
+
return path, gr.update(value=f"Excel ready: {os.path.basename(path)}", visible=True)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
# ── CSS ───────────────────────────────────────────────────────────────────────
|
| 175 |
+
|
| 176 |
+
CSS = """
|
| 177 |
+
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500&display=swap');
|
| 178 |
+
:root{--bg:#0c0c0c;--surf:#141414;--surf2:#1b1b1b;--border:#272727;--acc:#e8ff3b;--text:#eeebe4;--muted:#555;--r:3px;}
|
| 179 |
+
body,.gradio-container{background:var(--bg)!important;color:var(--text)!important;font-family:'DM Sans',sans-serif!important;}
|
| 180 |
+
#qheader{border-bottom:2px solid var(--acc);padding-bottom:14px;margin-bottom:28px;}
|
| 181 |
+
#qheader h1{font-family:'Bebas Neue',sans-serif;font-size:3.4rem;letter-spacing:.14em;color:var(--acc);margin:0;line-height:1;}
|
| 182 |
+
#qheader p{font-family:'DM Mono',monospace;font-size:.68rem;color:var(--muted);margin:5px 0 0 2px;letter-spacing:.2em;text-transform:uppercase;}
|
| 183 |
+
.sec{font-family:'Bebas Neue',sans-serif;font-size:1rem;letter-spacing:.2em;color:var(--muted);border-bottom:1px solid var(--border);padding-bottom:4px;margin:22px 0 10px;}
|
| 184 |
+
label,.label-wrap span{font-family:'DM Mono',monospace!important;font-size:.7rem!important;letter-spacing:.1em!important;text-transform:uppercase!important;color:var(--muted)!important;}
|
| 185 |
+
input[type=text],textarea,select{background:var(--surf)!important;border:1px solid var(--border)!important;border-radius:var(--r)!important;color:var(--text)!important;font-family:'DM Mono',monospace!important;font-size:.88rem!important;}
|
| 186 |
+
input[type=text]:focus,textarea:focus{border-color:var(--acc)!important;box-shadow:0 0 0 2px rgba(232,255,59,.12)!important;outline:none!important;}
|
| 187 |
+
button.primary{background:var(--acc)!important;color:#0c0c0c!important;font-family:'DM Mono',monospace!important;font-weight:500!important;letter-spacing:.08em!important;border:none!important;border-radius:var(--r)!important;}
|
| 188 |
+
button.primary:hover{background:#d4eb00!important;}
|
| 189 |
+
button.secondary{background:transparent!important;color:var(--text)!important;border:1px solid var(--border)!important;font-family:'DM Mono',monospace!important;letter-spacing:.07em!important;border-radius:var(--r)!important;}
|
| 190 |
+
button.secondary:hover{border-color:var(--acc)!important;color:var(--acc)!important;}
|
| 191 |
+
.dataframe{background:var(--surf)!important;border:1px solid var(--border)!important;font-family:'DM Mono',monospace!important;font-size:.78rem!important;}
|
| 192 |
+
.dataframe thead tr th{background:#1c1c1c!important;color:var(--acc)!important;border-bottom:2px solid var(--acc)!important;font-size:.65rem!important;letter-spacing:.18em!important;text-transform:uppercase!important;}
|
| 193 |
+
.dataframe tbody tr:nth-child(even){background:#111!important;}
|
| 194 |
+
.dataframe tbody tr:hover{background:#1e1e1e!important;}
|
| 195 |
+
.dataframe td{color:var(--text)!important;border-color:var(--border)!important;}
|
| 196 |
+
#status{font-family:'DM Mono',monospace!important;font-size:.76rem!important;padding:8px 14px!important;border-left:3px solid var(--acc)!important;background:#1a1a00!important;color:var(--acc)!important;border-radius:var(--r)!important;}
|
| 197 |
+
#footer{margin-top:32px;padding-top:12px;border-top:1px solid var(--border);font-family:'DM Mono',monospace;font-size:.62rem;color:#3a3a3a;letter-spacing:.15em;text-transform:uppercase;}
|
| 198 |
+
"""
|
| 199 |
+
|
| 200 |
+
# ── UI ────────────────────────────────────────────────────────────────────────
|
| 201 |
+
|
| 202 |
+
with gr.Blocks(css=CSS, title="Q-Sheet · Film") as demo:
|
| 203 |
+
|
| 204 |
+
session_state = gr.State({})
|
| 205 |
+
|
| 206 |
+
gr.HTML("""
|
| 207 |
+
<div id="qheader">
|
| 208 |
+
<h1>Q · SHEET</h1>
|
| 209 |
+
<p>Film & Short Film · Pro Tools Session Parser</p>
|
| 210 |
+
</div>""")
|
| 211 |
+
|
| 212 |
+
gr.HTML('<div class="sec">Project</div>')
|
| 213 |
+
project_name = gr.Textbox(placeholder="e.g. Ep 10 — Documentary 2025", label="Project / Film Title")
|
| 214 |
+
|
| 215 |
+
gr.HTML('<div class="sec">Import · Pro Tools Session Export (.txt)</div>')
|
| 216 |
+
with gr.Row():
|
| 217 |
+
pt_file = gr.File(label="Pro Tools track listing (.txt)", file_types=[".txt"], scale=3)
|
| 218 |
+
include_muted = gr.Checkbox(label="Include muted clips", value=False, scale=1)
|
| 219 |
+
btn_pt = gr.Button("⬆ Parse Pro Tools File", variant="primary")
|
| 220 |
+
session_info_box = gr.Textbox(label="Session Metadata", lines=4, interactive=False, visible=False)
|
| 221 |
+
|
| 222 |
+
status_box = gr.Textbox(label="", elem_id="status", visible=False, interactive=False)
|
| 223 |
+
|
| 224 |
+
gr.HTML('<div class="sec">Q-Sheet</div>')
|
| 225 |
+
table = gr.DataFrame(
|
| 226 |
+
value=empty_df(), headers=COLUMNS,
|
| 227 |
+
datatype=["number","str","str","str","str","str","str","str"],
|
| 228 |
+
interactive=False, wrap=False,
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
with gr.Accordion("✏ Add / Edit Cue Manually", open=False):
|
| 232 |
+
with gr.Row():
|
| 233 |
+
m_clip = gr.Textbox(placeholder="Sound name", label="Clip Name", scale=3)
|
| 234 |
+
m_track = gr.Textbox(placeholder="Track name", label="Track", scale=2)
|
| 235 |
+
with gr.Row():
|
| 236 |
+
m_start = gr.Textbox(placeholder="01:00:00:00", label="Start", scale=2)
|
| 237 |
+
m_end = gr.Textbox(placeholder="01:00:05:00", label="End", scale=2)
|
| 238 |
+
m_dur = gr.Textbox(placeholder="00:00:05:00", label="Duration", scale=2)
|
| 239 |
+
m_state = gr.Dropdown(["Unmuted","Muted"], value="Unmuted", label="State", scale=1)
|
| 240 |
+
with gr.Row():
|
| 241 |
+
btn_add = gr.Button("+ Add Cue", variant="primary", scale=2)
|
| 242 |
+
btn_delete = gr.Button("✕ Delete Last", variant="secondary", scale=1)
|
| 243 |
+
btn_clear = gr.Button("⌫ Clear All", variant="secondary", scale=1)
|
| 244 |
+
|
| 245 |
+
gr.HTML('<div class="sec">Export</div>')
|
| 246 |
+
with gr.Row():
|
| 247 |
+
btn_csv = gr.Button("↓ Export CSV", variant="secondary", scale=1)
|
| 248 |
+
btn_xlsx = gr.Button("↓ Export Excel", variant="secondary", scale=1)
|
| 249 |
+
csv_out = gr.File(label="Download CSV", interactive=False)
|
| 250 |
+
xlsx_out = gr.File(label="Download Excel", interactive=False)
|
| 251 |
+
|
| 252 |
+
with gr.Accordion("↑ Import existing Q-Sheet CSV", open=False):
|
| 253 |
+
csv_import = gr.File(label="Pick a CSV", file_types=[".csv"])
|
| 254 |
+
btn_csv_import = gr.Button("Load CSV", variant="secondary")
|
| 255 |
+
|
| 256 |
+
gr.HTML('<div id="footer">Timecode @ 25fps · Fade/crossfade clips removed automatically · Muted clips optional</div>')
|
| 257 |
+
|
| 258 |
+
# Wire-up
|
| 259 |
+
btn_pt.click(
|
| 260 |
+
import_protools_file,
|
| 261 |
+
inputs=[pt_file, include_muted],
|
| 262 |
+
outputs=[table, session_state, status_box, session_info_box],
|
| 263 |
+
).then(lambda info: gr.update(visible=bool(info)), inputs=[session_state], outputs=[session_info_box])
|
| 264 |
+
|
| 265 |
+
btn_add.click(add_entry, inputs=[m_clip, m_track, m_start, m_end, m_dur, m_state, table], outputs=[table, status_box])
|
| 266 |
+
btn_delete.click(delete_last, inputs=[table], outputs=[table, status_box])
|
| 267 |
+
btn_clear.click(clear_all, outputs=[table, status_box])
|
| 268 |
+
btn_csv.click(export_csv, inputs=[project_name, table], outputs=[csv_out, status_box])
|
| 269 |
+
btn_xlsx.click(export_xlsx, inputs=[project_name, table], outputs=[xlsx_out, status_box])
|
| 270 |
+
btn_csv_import.click(import_csv_file, inputs=[csv_import, table], outputs=[table, status_box])
|
| 271 |
+
|
| 272 |
+
if __name__ == "__main__":
|
| 273 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
pandas>=2.0.0
|
| 3 |
+
openpyxl>=3.1.0
|