Spaces:
Running
Running
File size: 1,980 Bytes
198f2fc a8c15c7 198f2fc 2af9152 198f2fc a8c15c7 198f2fc a8c15c7 198f2fc a8c15c7 198f2fc a8c15c7 198f2fc a8c15c7 198f2fc a8c15c7 198f2fc a8c15c7 198f2fc 2af9152 a8c15c7 2af9152 a8c15c7 2af9152 a8c15c7 2af9152 a8c15c7 2af9152 198f2fc a8c15c7 198f2fc | 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 | import gdown
import os
import re
from docx import Document
from datetime import datetime
def format_timestamp(seconds):
if seconds is None: return "00:00"
td = int(seconds)
minutes = td // 60
secs = td % 60
return f"{minutes:02d}:{secs:02d}"
def download_from_gdrive(url):
try:
if not os.path.exists("temp_downloads"): os.makedirs("temp_downloads")
output_path = f"temp_downloads/drive_audio_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp3"
return gdown.download(url, output_path, quiet=False, fuzzy=True)
except Exception as e:
print(f"Error: {e}")
return None
def clean_text(text):
"""
Uses Regex to find and remove repeating phrases like 'कर दो कर दो कर दो'.
"""
# Removes repetitions of 3 or more identical words
text = re.sub(r'(\b\w+\b)( \1){2,}', r'\1', text)
return text
def save_as_docx(transcripts):
doc = Document()
doc.add_heading('Hindi Transcription Report (Cleaned)', 0)
for entry in transcripts:
doc.add_heading(f"File: {entry['filename']}", level=1)
content = entry['text']
if isinstance(content, list):
last_text = ""
for chunk in content:
text = clean_text(chunk['text'])
# Skip if it's a hallucination (very high repetition in small chunk)
if text == last_text or len(text) < 2:
continue
ts = chunk.get('timestamp', (0, 0))
p = doc.add_paragraph()
p.add_run(f"[{format_timestamp(ts[0])}] ").bold = True
p.add_run(text)
last_text = text
else:
doc.add_paragraph(clean_text(content))
doc.add_page_break()
report_name = f"Transcripts_Cleaned_{datetime.now().strftime('%Y%m%d_%H%M%S')}.docx"
doc.save(report_name)
return report_name |