File size: 1,404 Bytes
16a7357
31cee8d
16a7357
 
 
 
 
31cee8d
 
 
 
 
 
 
16a7357
 
31cee8d
 
 
 
 
 
 
 
 
16a7357
31cee8d
 
16a7357
31cee8d
 
16a7357
31cee8d
 
 
16a7357
31cee8d
 
 
16a7357
13f54c7
16a7357
31cee8d
16a7357
 
31cee8d
16a7357
 
 
 
 
 
 
 
31cee8d
16a7357
 
 
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
import gradio as gr
import requests
from googletrans import Translator
import tempfile

translator = Translator()

# ⚠️ free public whisper API (demo)
WHISPER_API = "https://api-inference.huggingface.co/models/openai/whisper-small"

def format_time(i):
    start = i * 3
    end = start + 3
    return f"00:00:{start:02},000 --> 00:00:{end:02},000"

def process(video):
    # Read video file
    with open(video, "rb") as f:
        data = f.read()

    # Call HF API
    response = requests.post(WHISPER_API, data=data)
    
    if response.status_code != 200:
        return "API Error", None

    result = response.json()
    text = result.get("text", "")

    # Translate
    burmese = translator.translate(text, dest="my").text

    # Simple SRT
    sentences = burmese.split("။")
    srt = ""

    for i, s in enumerate(sentences):
        if s.strip():
            srt += f"{i+1}\n{format_time(i)}\n{s.strip()}။\n\n"

    # Save SRT
    tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".srt")
    tmp.write(srt.encode("utf-8"))
    tmp.close()

    return burmese, tmp.name

demo = gr.Interface(
    fn=process,
    inputs=gr.Video(label="Upload Video"),
    outputs=[
        gr.Textbox(label="🇲🇲 Burmese Script"),
        gr.File(label="⬇️ Download SRT")
    ],
    title="🔥 Burmese Video AI (ULTRA SAFE BUILD)"
)

demo.launch(server_name="0.0.0.0", server_port=7860)