Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,49 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
from googletrans import Translator
|
| 4 |
import tempfile
|
| 5 |
|
| 6 |
-
# Load model (CPU safe)
|
| 7 |
-
model = WhisperModel("tiny", device="cpu", compute_type="int8")
|
| 8 |
translator = Translator()
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
def process(video):
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
end = format_time(seg.end)
|
| 26 |
-
text = seg.text.strip()
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
# Save SRT
|
| 34 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".srt")
|
| 35 |
-
tmp.write(
|
| 36 |
tmp.close()
|
| 37 |
|
| 38 |
-
return
|
| 39 |
|
| 40 |
demo = gr.Interface(
|
| 41 |
fn=process,
|
|
@@ -44,7 +52,7 @@ demo = gr.Interface(
|
|
| 44 |
gr.Textbox(label="🇲🇲 Burmese Script"),
|
| 45 |
gr.File(label="⬇️ Download SRT")
|
| 46 |
],
|
| 47 |
-
title="🔥 Burmese Video AI (
|
| 48 |
)
|
| 49 |
|
| 50 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
from googletrans import Translator
|
| 4 |
import tempfile
|
| 5 |
|
|
|
|
|
|
|
| 6 |
translator = Translator()
|
| 7 |
|
| 8 |
+
# ⚠️ free public whisper API (demo)
|
| 9 |
+
WHISPER_API = "https://api-inference.huggingface.co/models/openai/whisper-small"
|
| 10 |
+
|
| 11 |
+
def format_time(i):
|
| 12 |
+
start = i * 3
|
| 13 |
+
end = start + 3
|
| 14 |
+
return f"00:00:{start:02},000 --> 00:00:{end:02},000"
|
| 15 |
|
| 16 |
def process(video):
|
| 17 |
+
# Read video file
|
| 18 |
+
with open(video, "rb") as f:
|
| 19 |
+
data = f.read()
|
| 20 |
+
|
| 21 |
+
# Call HF API
|
| 22 |
+
response = requests.post(WHISPER_API, data=data)
|
| 23 |
+
|
| 24 |
+
if response.status_code != 200:
|
| 25 |
+
return "API Error", None
|
| 26 |
|
| 27 |
+
result = response.json()
|
| 28 |
+
text = result.get("text", "")
|
| 29 |
|
| 30 |
+
# Translate
|
| 31 |
+
burmese = translator.translate(text, dest="my").text
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# Simple SRT
|
| 34 |
+
sentences = burmese.split("။")
|
| 35 |
+
srt = ""
|
| 36 |
|
| 37 |
+
for i, s in enumerate(sentences):
|
| 38 |
+
if s.strip():
|
| 39 |
+
srt += f"{i+1}\n{format_time(i)}\n{s.strip()}။\n\n"
|
| 40 |
|
| 41 |
# Save SRT
|
| 42 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".srt")
|
| 43 |
+
tmp.write(srt.encode("utf-8"))
|
| 44 |
tmp.close()
|
| 45 |
|
| 46 |
+
return burmese, tmp.name
|
| 47 |
|
| 48 |
demo = gr.Interface(
|
| 49 |
fn=process,
|
|
|
|
| 52 |
gr.Textbox(label="🇲🇲 Burmese Script"),
|
| 53 |
gr.File(label="⬇️ Download SRT")
|
| 54 |
],
|
| 55 |
+
title="🔥 Burmese Video AI (ULTRA SAFE BUILD)"
|
| 56 |
)
|
| 57 |
|
| 58 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|