Spaces:
Running
Running
File size: 10,594 Bytes
63008ca 1b24485 89f48e2 63008ca 638594e 63008ca 638594e 63008ca 4f790c1 0c04064 1b24485 59d7784 1831158 5c59053 1831158 59d7784 1831158 59d7784 5c59053 59d7784 1831158 59d7784 5c59053 59d7784 5c59053 1831158 5c59053 1831158 5c59053 638594e 5c59053 59d7784 1831158 5c59053 1831158 5c59053 1831158 5c59053 1831158 59d7784 5c59053 59d7784 1831158 59d7784 5c59053 1831158 5c59053 59d7784 1831158 5c59053 1831158 59d7784 5c59053 638594e 1831158 59d7784 1831158 59d7784 1831158 638594e 5c59053 1831158 5c59053 1831158 5c59053 1831158 5c59053 1831158 5c59053 1831158 5c59053 1831158 5c59053 1831158 5c59053 1831158 5c59053 1831158 59d7784 1831158 5c59053 59d7784 5c59053 1831158 5c59053 1831158 59d7784 1831158 59d7784 1831158 5c59053 1831158 59d7784 5c59053 59d7784 5c59053 1831158 59d7784 5c59053 1831158 59d7784 5c59053 1831158 5c59053 1831158 59d7784 5c59053 1831158 5c59053 638594e 1831158 638594e 5c59053 638594e 1831158 638594e 1831158 5c59053 1831158 638594e 5c59053 1831158 5c59053 1831158 5c59053 1831158 5c59053 638594e 1831158 5c59053 638594e 59d7784 638594e 87fae58 638594e 1831158 5c59053 59d7784 1831158 59d7784 1831158 59d7784 1aec502 59d7784 4f790c1 638594e 1831158 b045623 1831158 638594e 59d7784 1831158 59d7784 1831158 638594e 5c59053 1831158 5c59053 638594e af4bef5 1831158 638594e 1831158 638594e 63008ca 02cca7e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | import gradio as gr
import whisper
import yt_dlp
import os
import tempfile
models = {}
def load_model(model_name):
if model_name not in models:
models[model_name] = whisper.load_model(model_name)
return models[model_name]
def format_time(seconds):
m = int(seconds // 60)
s = int(seconds % 60)
ms = int((seconds % 1) * 10)
return f"{m:02d}:{s:02d}.{ms}"
# Simple Devanagari to Roman fallback map
DEVA_MAP = {
'अ':'a','आ':'aa','इ':'i','ई':'ii','उ':'u','ऊ':'uu','ए':'e','ऐ':'ai',
'ओ':'o','औ':'au','क':'k','ख':'kh','ग':'g','घ':'gh','च':'ch','छ':'chh',
'ज':'j','झ':'jh','ट':'t','ड':'d','त':'t','थ':'th','द':'d','ध':'dh',
'न':'n','प':'p','फ':'ph','ब':'b','भ':'bh','म':'m','य':'y','र':'r',
'ल':'l','व':'v','श':'sh','ष':'sh','स':'s','ह':'h','ं':'n','ः':'h',
'ा':'a','ि':'i','ी':'i','ु':'u','ू':'u','े':'e','ै':'ai','ो':'o',
'ौ':'au','्':'','ळ':'l','क्ष':'ksh','ज्ञ':'gya','ड़':'r','ढ़':'rh',
'ऑ':'o','ऍ':'e','ॉ':'o','।':'.','॥':'.','ऋ':'ri','ॠ':'ri',
'ग़':'g','ज़':'z','फ़':'f','ड़':'r','ढ़':'rh','ञ':'n','ण':'n','ङ':'n',
}
def devanagari_to_roman(text):
result = []
for ch in text:
result.append(DEVA_MAP.get(ch, ch))
return ''.join(result)
custom_css = """
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@1&family=Geist:wght@300;400;500;600&display=swap');
*, *::before, *::after { box-sizing: border-box; }
body, .gradio-container {
background: #0a0a0a !important;
font-family: 'Geist', sans-serif !important;
color: #ededed !important;
}
.gradio-container {
max-width: 1080px !important;
margin: 0 auto !important;
padding: 0 !important;
}
/* NAV / Header */
.prose {
padding: 0 40px !important;
height: 56px !important;
display: flex !important;
align-items: center !important;
justify-content: space-between !important;
border-bottom: 1px solid #1a1a1a !important;
margin-bottom: 0 !important;
}
.prose h1 {
font-family: 'Geist', sans-serif !important;
font-size: 13px !important;
font-weight: 600 !important;
color: #ededed !important;
letter-spacing: -0.02em !important;
line-height: 1 !important;
margin: 0 !important;
}
.prose h1 em {
font-family: 'Instrument Serif', serif !important;
font-style: italic !important;
font-weight: 400 !important;
color: #58B8FF !important;
font-size: 14px !important;
}
.prose p {
font-size: 10px !important;
color: #2a2a2a !important;
letter-spacing: 0.14em !important;
margin: 0 !important;
}
/* Layout */
.contain, .gap { background: transparent !important; border: none !important; }
.block {
background: #0f0f0f !important;
border: 1px solid #1a1a1a !important;
border-radius: 10px !important;
}
.block label > span, label > span {
font-family: 'Geist', sans-serif !important;
font-size: 10px !important;
font-weight: 500 !important;
color: #333 !important;
text-transform: uppercase !important;
letter-spacing: 0.16em !important;
}
/* File upload */
[data-testid="file"], .file {
background: #0a0a0a !important;
border: 1px dashed #1a2d3a !important;
border-radius: 12px !important;
min-height: 160px !important;
transition: all 0.2s !important;
}
[data-testid="file"]:hover {
border-color: #3066BE !important;
background: #060d18 !important;
}
/* Dropdowns */
.wrap-inner, select {
background: #0a0a0a !important;
border: 1px solid #1a1a1a !important;
border-radius: 8px !important;
color: #ededed !important;
font-family: 'Geist', sans-serif !important;
font-size: 12px !important;
}
/* Radio */
input[type="radio"] { accent-color: #3066BE !important; }
input[type="checkbox"] { accent-color: #3066BE !important; }
/* Textarea */
textarea {
background: transparent !important;
color: #c8c8c8 !important;
font-family: 'Geist', sans-serif !important;
font-size: 14px !important;
line-height: 1.9 !important;
font-weight: 300 !important;
border: none !important;
}
textarea::placeholder { color: #1a1a1a !important; font-style: italic !important; }
/* Primary button */
button.primary {
background: #ededed !important;
border: none !important;
border-radius: 8px !important;
color: #000 !important;
font-family: 'Geist', sans-serif !important;
font-size: 12px !important;
font-weight: 600 !important;
letter-spacing: 0.04em !important;
padding: 12px 28px !important;
transition: all 0.18s ease !important;
width: 100% !important;
}
button.primary:hover {
background: #58B8FF !important;
color: #000 !important;
}
/* Secondary button */
button.secondary {
background: transparent !important;
border: 1px solid #1a1a1a !important;
border-radius: 8px !important;
color: #333 !important;
font-family: 'Geist', sans-serif !important;
font-size: 12px !important;
font-weight: 600 !important;
letter-spacing: 0.04em !important;
padding: 12px 28px !important;
transition: all 0.18s ease !important;
width: 100% !important;
}
button.secondary:hover {
border-color: #3066BE !important;
color: #58B8FF !important;
}
/* Tabs */
.tab-nav { border-bottom: 1px solid #141414 !important; }
.tab-nav button {
font-family: 'Geist', sans-serif !important;
font-size: 11px !important;
font-weight: 500 !important;
letter-spacing: 0.12em !important;
text-transform: uppercase !important;
color: #333 !important;
background: transparent !important;
border: none !important;
border-bottom: 1.5px solid transparent !important;
padding: 12px 20px !important;
transition: all 0.15s !important;
}
.tab-nav button.selected {
color: #ededed !important;
border-bottom-color: #3066BE !important;
}
/* Progress bar */
.progress-bar { background: #3066BE !important; }
.progress-bar-wrap { background: #111 !important; border-radius: 0 !important; }
/* Scrollbar */
::-webkit-scrollbar { width: 2px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1a2030; }
footer { display: none !important; }
"""
LANGUAGES = [
"Auto Detect", "English", "Hinglish (Roman)", "Hindi", "Spanish", "French",
"German", "Italian", "Portuguese", "Chinese", "Japanese",
"Korean", "Arabic", "Russian", "Dutch", "Turkish"
]
MODEL_INFO = {
"tiny": "Fastest — best for short clips",
"base": "Fast — good everyday accuracy",
"small": "Balanced — recommended",
"medium": "Best accuracy — slower processing"
}
with gr.Blocks(title="Kalp Transcript — Kalpi Edition") as demo:
gr.Markdown("""
# Kalp *Transcript*
by Kalpi Edition
""")
with gr.Row():
with gr.Column(scale=5):
file_input = gr.File(
label="Drop your file here — MP4 · MOV · MP3 · WAV · M4A"
)
with gr.Row():
model_choice = gr.Dropdown(
choices=[
"tiny — Fastest",
"base — Fast",
"small — Balanced",
"medium — Best accuracy",
"large-v3 — Most accurate (very slow)"
],
value="tiny — Fastest",
label="Model"
)
language = gr.Dropdown(
choices=LANGUAGES,
value="Auto Detect",
label="Language"
)
with gr.Row():
translate = gr.Dropdown(
choices=["Off", "Translate to English"],
value="Off",
label="Translate"
)
timestamps = gr.Checkbox(
label="Show timestamps",
value=False
)
gr.Markdown("<div style='height:4px'></div>")
submit_btn = gr.Button("Transcribe →", variant="primary")
clear_btn = gr.ClearButton(value="Clear", variant="secondary")
with gr.Column(scale=6):
with gr.Tabs():
with gr.Tab("Transcript"):
output = gr.Textbox(
label="",
lines=18,
placeholder="Your transcript will appear here..."
)
with gr.Tab("Download .txt"):
plain_output = gr.Textbox(label="", lines=12, visible=False)
gr.Markdown("<div style='height:6px'></div>")
download_btn = gr.Button("Save transcript", variant="secondary")
download_file = gr.File(label="")
def transcribe(file, model_name, language, show_timestamps, translate):
if file is None:
return "⚠️ Please upload a file first.", ""
model = load_model(model_name)
lang = None if language == "Auto Detect" else language
task = "translate" if translate == "Translate to English" else "transcribe"
# Handle Hinglish — transcribe in Hindi then romanize output
if language == "Hinglish (Roman)":
lang = "hi"
result = model.transcribe(file.name, language=lang, task=task)
for seg in result["segments"]:
seg["text"] = devanagari_to_roman(seg["text"])
result["text"] = devanagari_to_roman(result["text"])
else:
result = model.transcribe(file.name, language=lang, task=task)
if show_timestamps:
lines = []
for seg in result["segments"]:
start = format_time(seg["start"])
end = format_time(seg["end"])
lines.append(f"[{start} → {end}] {seg['text'].strip()}")
transcript = "\n".join(lines)
else:
transcript = result["text"].strip()
return transcript, transcript
def run(file, model_raw, language, timestamps, translate):
model_name = model_raw.split()[0].strip()
return transcribe(file, model_name, language, timestamps, translate)
submit_btn.click(
fn=run,
inputs=[file_input, model_choice, language, timestamps, translate],
outputs=[output, plain_output]
)
if __name__ == "__main__":
demo.launch(css=custom_css)
|