Spaces:
Running
Running
Update app.py
#1
by konay233 - opened
app.py
CHANGED
|
@@ -10,27 +10,16 @@ import time
|
|
| 10 |
import numpy as np
|
| 11 |
import re
|
| 12 |
import json
|
| 13 |
-
import uuid # 👈 Session ID ထုတ်ရန်အတွက် Import လုပ်ခြင်း
|
| 14 |
from google import genai
|
| 15 |
from datetime import datetime, date
|
| 16 |
from PIL import Image, ImageDraw, ImageFont
|
| 17 |
|
| 18 |
# =====================================================================
|
| 19 |
-
# ⚙️ SECURITY SETTINGS & LOGIN CONFIG
|
| 20 |
# =====================================================================
|
| 21 |
MAX_SUBTITLE_DURATION_SECONDS = 7.0
|
| 22 |
-
|
| 23 |
-
# 👥 LOGIN ACCOUNTS CONFIG (အကောင့်တစ်ခုတည်းကို လူအများ မျှသုံးနိုင်ပါသည်)
|
| 24 |
-
ACCOUNTS = {
|
| 25 |
-
"user1": "123123", # Free User (Session/Browser အလိုက် တစ်ရက် ၂ ပုဒ်)
|
| 26 |
-
"admin": "admin789" # Admin User (Unlimited)
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
EXPIRY_DATE_STR = "2026-8-31"
|
| 30 |
|
| 31 |
-
# 🛑 USER RATE LIMIT TRACKER (Session/Browser ID အလိုက် ရေတွက်မည်)
|
| 32 |
-
USER_LIMIT_TRACKER = {}
|
| 33 |
-
|
| 34 |
SYSTEM_INSTRUCTION = "You are a professional movie recap writer. Translate movie subtitle lines into natural, engaging, and thrilling Burmese movie recap style. Keep it concise."
|
| 35 |
MODEL_NAME = "gemini-2.5-flash"
|
| 36 |
|
|
@@ -209,50 +198,17 @@ def generate_voice_sync(text, voice_id, filename, desired_speed, target_duration
|
|
| 209 |
loop.run_until_complete(_async_gen())
|
| 210 |
|
| 211 |
# =====================================================================
|
| 212 |
-
# 🎬 HIGH-SPEED PRODUCTION AUTOMATION ENGINE
|
| 213 |
# =====================================================================
|
| 214 |
def process_magic_recap_video(
|
| 215 |
video_path, user_api_key, ratio_select, background_fill, enable_zoom, zoom_level,
|
| 216 |
logo_file, mirror_flip, filter_color, voice_gender, tone_style,
|
| 217 |
text_color, stroke_color, blur_y_percent, blur_strength, sub_pos_percent, desired_speed,
|
| 218 |
-
session_id, # 👈 Browser Session State
|
| 219 |
-
request: gr.Request,
|
| 220 |
progress=gr.Progress(track_tqdm=True)
|
| 221 |
):
|
| 222 |
is_valid, msg = check_app_expiry()
|
| 223 |
if not is_valid: raise gr.Error(msg)
|
| 224 |
if not video_path: return None
|
| 225 |
-
|
| 226 |
-
# 🛑 LOGIN ACCOUNT & SESSION ID ယူခြင်း
|
| 227 |
-
login_username = request.username if (request and hasattr(request, 'username')) else "user1"
|
| 228 |
-
|
| 229 |
-
if login_username == "admin":
|
| 230 |
-
user_identifier = "admin"
|
| 231 |
-
else:
|
| 232 |
-
# Browser Session ID ဖြင့် လူတစ်ဦးစီကို သီးခြား ခွဲခြားမည်
|
| 233 |
-
user_identifier = f"session_{session_id}"
|
| 234 |
-
|
| 235 |
-
current_timestamp = time.time()
|
| 236 |
-
print(f"👤 အသုံးပြုသူ Account: {login_username} | Identifier: {user_identifier}")
|
| 237 |
-
|
| 238 |
-
# Admin မဟုတ်ပါက Session/Browser အလိုက် ၁ ရက် (၂) ပုဒ် Limit စစ်ဆေးမည်
|
| 239 |
-
if user_identifier != "admin":
|
| 240 |
-
if user_identifier in USER_LIMIT_TRACKER:
|
| 241 |
-
user_data = USER_LIMIT_TRACKER[user_identifier]
|
| 242 |
-
first_time = user_data["first_time"]
|
| 243 |
-
count = user_data["count"]
|
| 244 |
-
elapsed_time = current_timestamp - first_time
|
| 245 |
-
|
| 246 |
-
if elapsed_time < 86400: # ၂၄ နာရီ အတွင်း
|
| 247 |
-
if count >= 2: # ၂ ပုဒ် ပြည့်ပါက တားဆီးမည်
|
| 248 |
-
remaining_seconds = 86400 - elapsed_time
|
| 249 |
-
rem_hours = int(remaining_seconds // 3600)
|
| 250 |
-
rem_mins = int((remaining_seconds % 3600) // 60)
|
| 251 |
-
raise gr.Error(f"❌ ခွင့်ပြုချက်ကျော်လွန်နေပါသည်။ သင့် Browser မှ တစ်ရက်လျှင် ဗီဒီယို (၂) ပုဒ်သာ ထုတ်ယူခွင့်ရှိသည်။ ပြန်လည်စမ်းသပ်ရန် {rem_hours} နာရီ {rem_mins} မိနစ် လိုအပ်ပါသေးသည်။")
|
| 252 |
-
else:
|
| 253 |
-
USER_LIMIT_TRACKER[user_identifier] = {"count": 0, "first_time": current_timestamp}
|
| 254 |
-
else:
|
| 255 |
-
USER_LIMIT_TRACKER[user_identifier] = {"count": 0, "first_time": current_timestamp}
|
| 256 |
|
| 257 |
temp_dir = "temp_space_workspace"
|
| 258 |
if os.path.exists(temp_dir): shutil.rmtree(temp_dir)
|
|
@@ -463,11 +419,6 @@ def process_magic_recap_video(
|
|
| 463 |
|
| 464 |
if os.path.exists(temp_dir): shutil.rmtree(temp_dir)
|
| 465 |
|
| 466 |
-
# 📈 ဗီဒီယို အောင်မြင်စွာ ထုတ်ယူပြီးမှသာ ထို Session ၏ Count ကို ၁ တိုးမည်
|
| 467 |
-
if user_identifier != "admin":
|
| 468 |
-
USER_LIMIT_TRACKER[user_identifier]["count"] += 1
|
| 469 |
-
print(f"✅ [{user_identifier}] ဗီဒီယိုထုတ်ယူမှု အောင်မြင်ပါသည်။ ယနေ့ ထုတ်ယူပြီးစီးမှု: {USER_LIMIT_TRACKER[user_identifier]['count']} ကြိ���်")
|
| 470 |
-
|
| 471 |
return output_video_path
|
| 472 |
|
| 473 |
except Exception as e:
|
|
@@ -481,16 +432,11 @@ def create_main_app_interface():
|
|
| 481 |
is_valid, msg = check_app_expiry()
|
| 482 |
|
| 483 |
with gr.Blocks() as main_app:
|
| 484 |
-
|
| 485 |
-
session_id_state = gr.State(lambda: str(uuid.uuid4()))
|
| 486 |
-
|
| 487 |
-
gr.Markdown("<h1 style='text-align: center; color: #5B50F3;'>✨ Video Auto Recap (Multi-Account) ✨</h1>")
|
| 488 |
if not is_valid:
|
| 489 |
gr.Markdown(f"### {msg}")
|
| 490 |
return main_app
|
| 491 |
|
| 492 |
-
gr.Markdown("<div style='background-color: #333; padding: 10px; border-radius: 8px; text-align: center; color: #fff;'>📢 <b>Free App Rules:</b> တစ်ရက်လျှင် Video (၂) ပုဒ် အခမဲ့ ထုတ်ယူခွင့် ရှိပါသည်</div>")
|
| 493 |
-
|
| 494 |
with gr.Row():
|
| 495 |
with gr.Column(scale=2):
|
| 496 |
video_input = gr.Video(label="🎥 ဗီဒီယို ထည့်ရန်", sources=["upload"])
|
|
@@ -533,20 +479,14 @@ def create_main_app_interface():
|
|
| 533 |
inputs=[
|
| 534 |
video_input, user_api_key, ratio_select, background_fill, enable_zoom, zoom_level,
|
| 535 |
logo_file, mirror_flip, filter_color, voice_select, tone_style, text_color_input,
|
| 536 |
-
stroke_color_input, blur_y_percent, blur_strength, sub_pos_percent, desired_speed
|
| 537 |
-
session_id_state # 👈 session_id ကို Function ထဲ ပို့ပေးခြင်း
|
| 538 |
],
|
| 539 |
outputs=[output_video]
|
| 540 |
)
|
| 541 |
|
| 542 |
return main_app
|
| 543 |
|
| 544 |
-
def verify_member(username, password):
|
| 545 |
-
if username in ACCOUNTS and ACCOUNTS[username] == password:
|
| 546 |
-
return True
|
| 547 |
-
return False
|
| 548 |
-
|
| 549 |
demo_app = create_main_app_interface()
|
| 550 |
|
| 551 |
if __name__ == "__main__":
|
| 552 |
-
demo_app.launch(
|
|
|
|
| 10 |
import numpy as np
|
| 11 |
import re
|
| 12 |
import json
|
|
|
|
| 13 |
from google import genai
|
| 14 |
from datetime import datetime, date
|
| 15 |
from PIL import Image, ImageDraw, ImageFont
|
| 16 |
|
| 17 |
# =====================================================================
|
| 18 |
+
# ⚙️ SECURITY SETTINGS & LOGIN CONFIG (Modified: Login & Limits Removed)
|
| 19 |
# =====================================================================
|
| 20 |
MAX_SUBTITLE_DURATION_SECONDS = 7.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
EXPIRY_DATE_STR = "2026-8-31"
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
SYSTEM_INSTRUCTION = "You are a professional movie recap writer. Translate movie subtitle lines into natural, engaging, and thrilling Burmese movie recap style. Keep it concise."
|
| 24 |
MODEL_NAME = "gemini-2.5-flash"
|
| 25 |
|
|
|
|
| 198 |
loop.run_until_complete(_async_gen())
|
| 199 |
|
| 200 |
# =====================================================================
|
| 201 |
+
# 🎬 HIGH-SPEED PRODUCTION AUTOMATION ENGINE (Limits Removed)
|
| 202 |
# =====================================================================
|
| 203 |
def process_magic_recap_video(
|
| 204 |
video_path, user_api_key, ratio_select, background_fill, enable_zoom, zoom_level,
|
| 205 |
logo_file, mirror_flip, filter_color, voice_gender, tone_style,
|
| 206 |
text_color, stroke_color, blur_y_percent, blur_strength, sub_pos_percent, desired_speed,
|
|
|
|
|
|
|
| 207 |
progress=gr.Progress(track_tqdm=True)
|
| 208 |
):
|
| 209 |
is_valid, msg = check_app_expiry()
|
| 210 |
if not is_valid: raise gr.Error(msg)
|
| 211 |
if not video_path: return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
temp_dir = "temp_space_workspace"
|
| 214 |
if os.path.exists(temp_dir): shutil.rmtree(temp_dir)
|
|
|
|
| 419 |
|
| 420 |
if os.path.exists(temp_dir): shutil.rmtree(temp_dir)
|
| 421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
return output_video_path
|
| 423 |
|
| 424 |
except Exception as e:
|
|
|
|
| 432 |
is_valid, msg = check_app_expiry()
|
| 433 |
|
| 434 |
with gr.Blocks() as main_app:
|
| 435 |
+
gr.Markdown("<h1 style='text-align: center; color: #5B50F3;'>✨ Video Auto Recap (Unlimited) ✨</h1>")
|
|
|
|
|
|
|
|
|
|
| 436 |
if not is_valid:
|
| 437 |
gr.Markdown(f"### {msg}")
|
| 438 |
return main_app
|
| 439 |
|
|
|
|
|
|
|
| 440 |
with gr.Row():
|
| 441 |
with gr.Column(scale=2):
|
| 442 |
video_input = gr.Video(label="🎥 ဗီဒီယို ထည့်ရန်", sources=["upload"])
|
|
|
|
| 479 |
inputs=[
|
| 480 |
video_input, user_api_key, ratio_select, background_fill, enable_zoom, zoom_level,
|
| 481 |
logo_file, mirror_flip, filter_color, voice_select, tone_style, text_color_input,
|
| 482 |
+
stroke_color_input, blur_y_percent, blur_strength, sub_pos_percent, desired_speed
|
|
|
|
| 483 |
],
|
| 484 |
outputs=[output_video]
|
| 485 |
)
|
| 486 |
|
| 487 |
return main_app
|
| 488 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
demo_app = create_main_app_interface()
|
| 490 |
|
| 491 |
if __name__ == "__main__":
|
| 492 |
+
demo_app.launch(theme=gr.themes.Default())
|