Update app.py
Browse files123456789107 unmodified lines1819202122232421 unmodified lines4647484950515253545556575859604 unmodified lines65666768697071import osimport reimport timeimport gradio as grfrom google import genaifrom google.genai import typesdef generate_srt_from_video(video_path, api_key, progress=gr.Progress()):if not api_key or not api_key.strip():return None, "❌ Google AI Studio API Key ထည့်သွင်းပါ။"7 unmodified linesprogress(0.3, desc="ဗီဒီယိုကို Gemini API သို့ Upload တင်နေသည်...")video_file = client.files.upload(file=video_path)# Video Processing စောင့်ရန်while video_file.state.name == "PROCESSING":time.sleep(2)video_file = client.files.get(name=video_file.name)21 unmodified linescontents=[video_file, prompt])# Gemini Upload File ကို ပြန်ရှင်းပစ်ရန်client.files.delete(name=video_file.name)srt_content = response.text.strip()# Codeblock mark တွေ ပါလာပါက ရှင်းထုတ်ခြင်းsrt_content = re.sub(r'^```\w*\n', '', srt_content)srt_content = re.sub(r'\n```$', '', srt_content)# .srt File အဖြစ် Save ပြုလုပ်ခြင်းsrt_filename = "output_myanmar.srt"with open(srt_filename, "w", encoding="utf-8") as f:f.write(srt_content)4 unmodified linesexcept Exception as e:return None, f"❌ Error: {str(e)}"# Gradio Interface Build ပြုလုပ်ခြင်းwith gr.Blocks(title="Chinese Video to Myanmar Subtitle SRT") as app:gr.Markdown("# 🎬 Chinese Video to Myanmar Subtitle (.srt) Generator")gr.Markdown("Short Video များမှ တရုတ်/အင်္ဂလိပ် အသံကို ကြည့်ပြီး Timeframe ကိုက်ညီသော မြန်မာ Subtitle (.srt) ဖိုင် ထုတ်ပေးသည့် စနစ်")12345678910117 unmodified lines19202122232421 unmodified lines4647484950515253545556574 unmodified lines626364656667import osimport reimport timeimport spacesimport gradio as grfrom google import genai@spaces.GPUdef generate_srt_from_video(video_path, api_key, progress=gr.Progress()):if not api_key or not api_key.strip():return None, "❌ Google AI Studio API Key ထည့်သွင်းပါ။"7 unmodified linesprogress(0.3, desc="ဗီဒီယိုကို Gemini API သို့ Upload တင်နေသည်...")video_file = client.files.upload(file=video_path)while video_file.state.name == "PROCESSING":time.sleep(2)video_file = client.files.get(name=video_file.name)21 unmodified linescontents=[video_file, prompt])client.files.delete(name=video_file.name)srt_content = response.text.strip()srt_content = re.sub(r'^```\w*\n', '', srt_content)srt_content = re.sub(r'\n```$', '', srt_content)srt_filename = "output_myanmar.srt"with open(srt_filename, "w", encoding="utf-8") as f:f.write(srt_content)4 unmodified linesexcept Exception as e:return None, f"❌ Error: {str(e)}"with gr.Blocks(title="Chinese Video to Myanmar Subtitle SRT") as app:gr.Markdown("# 🎬 Chinese Video to Myanmar Subtitle (.srt) Generator")gr.Markdown("Short Video များမှ တရုတ်/အင်္ဂလိပ် အသံကို ကြည့်ပြီး Timeframe ကိုက်ညီသော မြန်မာ Subtitle (.srt) ဖိုင် ထုတ်ပေးသည့် စနစ်")
app.py+2-6