File size: 1,921 Bytes
32c9224
 
00a56e2
e794ecb
 
5c6bee1
 
32c9224
5c6bee1
00a56e2
 
42f3b5d
00a56e2
e794ecb
5c6bee1
 
 
e794ecb
5c6bee1
 
 
e794ecb
 
 
 
5c6bee1
 
e794ecb
 
 
 
 
 
 
 
 
 
5c6bee1
e794ecb
 
5c6bee1
 
e794ecb
 
 
 
 
 
5c6bee1
e794ecb
fa707db
fbd8841
00a56e2
e794ecb
 
 
 
 
5c6bee1
 
32c9224
 
fbd8841
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
import gradio as gr
import whisper
from googletrans import Translator
import srt
import datetime
import tempfile
import os

# Load model once
model = whisper.load_model("base")
translator = Translator()

def transcribe(audio):
    try:
        # Check if audio file exists
        if audio is None:
            return "โŒ No audio uploaded!", None

        # Transcribe audio
        result = model.transcribe(audio)
        segments = result.get("segments", [])
        subtitles = []
        full_text = ""

        for i, seg in enumerate(segments):
            start = datetime.timedelta(seconds=float(seg["start"]))
            end = datetime.timedelta(seconds=float(seg["end"]))
            text = seg["text"].strip()

            # Translate Hindi โ†’ Hinglish (pronunciation)
            translated = translator.translate(text, src='hi', dest='en').pronunciation
            if not translated:
                translated = translator.translate(text, src='hi', dest='en').text

            subtitles.append(srt.Subtitle(index=i+1, start=start, end=end, content=translated))
            full_text += translated + " "

        # Create SRT file
        srt_content = srt.compose(subtitles)

        # Temporary file save
        srt_path = os.path.join(tempfile.gettempdir(), "output.srt")
        with open(srt_path, "w", encoding="utf-8") as f:
            f.write(srt_content)

        return full_text.strip(), srt_path

    except Exception as e:
        return f"โŒ Runtime Error: {str(e)}", None


iface = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(source="upload", type="filepath", label="๐ŸŽค Upload Hindi Audio"),
    outputs=[
        gr.Textbox(label="๐Ÿ“ Hinglish Subtitles"),
        gr.File(label="โฌ‡๏ธ Download SRT File")
    ],
    title="Hinglish Subtitle Generator ๐Ÿ‡ฎ๐Ÿ‡ณ",
    description="Upload Hindi speech audio โ€” get Hinglish subtitles (.srt) instantly!"
)

iface.launch()