Update app.py
Browse files
app.py
CHANGED
|
@@ -5,20 +5,21 @@ import random
|
|
| 5 |
import tempfile
|
| 6 |
import shutil
|
| 7 |
import time
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
CATEGORIAS = ["AVATAR WORLD", "BLOX FRUITS", "TOCA LIFE", "FC MOBILE"]
|
| 11 |
BASE_ASSETS = "assets"
|
| 12 |
for cat in CATEGORIAS:
|
| 13 |
os.makedirs(os.path.join(BASE_ASSETS, cat, "cortes"), exist_ok=True)
|
| 14 |
-
# ====================================================================
|
| 15 |
-
|
| 16 |
-
st.set_page_config(page_title="Shorts Generator", layout="centered")
|
| 17 |
-
st.title("🎥 Shorts Generator - Simples")
|
| 18 |
|
| 19 |
st.markdown("Envie seus vídeos e gere conteúdo com efeitos e controle total de duração!")
|
| 20 |
|
| 21 |
-
# ============
|
| 22 |
categoria_selecionada = st.selectbox(
|
| 23 |
"Escolha a categoria (opcional, para usar cortes já salvos):",
|
| 24 |
["Selecione..."] + CATEGORIAS
|
|
@@ -34,8 +35,7 @@ if categoria_selecionada != "Selecione...":
|
|
| 34 |
if f.lower().endswith(".mp4")
|
| 35 |
]
|
| 36 |
st.caption(f"Encontrados {len(cortes_salvos_paths)} cortes salvos em: {path_cortes_salvos}")
|
| 37 |
-
# ====================================================================
|
| 38 |
-
|
| 39 |
# Upload dos vídeos (MANTIDO)
|
| 40 |
cortes = st.file_uploader("Envie os vídeos de cortes", type=["mp4"], accept_multiple_files=True)
|
| 41 |
|
|
@@ -62,6 +62,7 @@ crf_value = st.slider("Qualidade CRF (menor = melhor qualidade)", 18, 30, 18)
|
|
| 62 |
st.write("### Outros")
|
| 63 |
ativar_espelhar = st.checkbox("Espelhar Vídeo", value=True)
|
| 64 |
ativar_filtro_cor = st.checkbox("Filtro de Cor (Contraste/Saturação)", value=True)
|
|
|
|
| 65 |
# Botão principal (MANTIDO, mas agora combinando uploads + salvos)
|
| 66 |
if st.button("Gerar Vídeo(s)"):
|
| 67 |
# Verifica se temos pelo menos upload OU salvos
|
|
@@ -185,3 +186,67 @@ if st.button("Gerar Vídeo(s)"):
|
|
| 185 |
st.error(f"Erro inesperado: {str(e)}")
|
| 186 |
finally:
|
| 187 |
shutil.rmtree(temp_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import shutil
|
| 7 |
import time
|
| 8 |
+
import base64 # <— NOVO
|
| 9 |
|
| 10 |
+
st.set_page_config(page_title="Shorts Generator", layout="centered")
|
| 11 |
+
st.title("🎥 Shorts Generator - Simples")
|
| 12 |
+
|
| 13 |
+
# ============ NOVO: categorias e pastas de cortes salvos ============
|
| 14 |
CATEGORIAS = ["AVATAR WORLD", "BLOX FRUITS", "TOCA LIFE", "FC MOBILE"]
|
| 15 |
BASE_ASSETS = "assets"
|
| 16 |
for cat in CATEGORIAS:
|
| 17 |
os.makedirs(os.path.join(BASE_ASSETS, cat, "cortes"), exist_ok=True)
|
| 18 |
+
# ====================================================================
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
st.markdown("Envie seus vídeos e gere conteúdo com efeitos e controle total de duração!")
|
| 21 |
|
| 22 |
+
# ============ NOVO: seleção de categoria para cortes salvos =========
|
| 23 |
categoria_selecionada = st.selectbox(
|
| 24 |
"Escolha a categoria (opcional, para usar cortes já salvos):",
|
| 25 |
["Selecione..."] + CATEGORIAS
|
|
|
|
| 35 |
if f.lower().endswith(".mp4")
|
| 36 |
]
|
| 37 |
st.caption(f"Encontrados {len(cortes_salvos_paths)} cortes salvos em: {path_cortes_salvos}")
|
| 38 |
+
# ====================================================================
|
|
|
|
| 39 |
# Upload dos vídeos (MANTIDO)
|
| 40 |
cortes = st.file_uploader("Envie os vídeos de cortes", type=["mp4"], accept_multiple_files=True)
|
| 41 |
|
|
|
|
| 62 |
st.write("### Outros")
|
| 63 |
ativar_espelhar = st.checkbox("Espelhar Vídeo", value=True)
|
| 64 |
ativar_filtro_cor = st.checkbox("Filtro de Cor (Contraste/Saturação)", value=True)
|
| 65 |
+
|
| 66 |
# Botão principal (MANTIDO, mas agora combinando uploads + salvos)
|
| 67 |
if st.button("Gerar Vídeo(s)"):
|
| 68 |
# Verifica se temos pelo menos upload OU salvos
|
|
|
|
| 186 |
st.error(f"Erro inesperado: {str(e)}")
|
| 187 |
finally:
|
| 188 |
shutil.rmtree(temp_dir)
|
| 189 |
+
st.markdown("---")
|
| 190 |
+
st.subheader("🔐 Admin — Enviar cortes para o sistema (opcional)")
|
| 191 |
+
|
| 192 |
+
# Mesma senha do seu primeiro código: base64 de "admin123"
|
| 193 |
+
SENHA_CODIFICADA = "YWRtaW4xMjM="
|
| 194 |
+
|
| 195 |
+
if "autenticado_admin" not in st.session_state:
|
| 196 |
+
st.session_state.autenticado_admin = False
|
| 197 |
+
|
| 198 |
+
if not st.session_state.autenticado_admin:
|
| 199 |
+
colA, colB = st.columns([3, 1])
|
| 200 |
+
with colA:
|
| 201 |
+
senha_input = st.text_input("Senha do Admin:", type="password", help="Dica: é a mesma do outro app 😉")
|
| 202 |
+
with colB:
|
| 203 |
+
if st.button("Entrar"):
|
| 204 |
+
if base64.b64encode(senha_input.encode()).decode() == SENHA_CODIFICADA:
|
| 205 |
+
st.session_state.autenticado_admin = True
|
| 206 |
+
st.success("✅ Acesso liberado!")
|
| 207 |
+
else:
|
| 208 |
+
st.error("❌ Senha incorreta.")
|
| 209 |
+
else:
|
| 210 |
+
st.success("✅ Você está autenticado.")
|
| 211 |
+
|
| 212 |
+
cat_admin = st.selectbox("Categoria para salvar os cortes:", CATEGORIAS, key="cat_admin_upload")
|
| 213 |
+
pasta_admin = os.path.join(BASE_ASSETS, cat_admin, "cortes")
|
| 214 |
+
st.caption(f"Pasta de destino: `{pasta_admin}`")
|
| 215 |
+
|
| 216 |
+
arquivos_admin = st.file_uploader(
|
| 217 |
+
"Envie os arquivos de CORTES (.mp4) para esta categoria",
|
| 218 |
+
type=["mp4"], accept_multiple_files=True, key="admin_uploader"
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
if arquivos_admin:
|
| 222 |
+
with st.spinner("⏳ Processando e padronizando cortes..."):
|
| 223 |
+
for f in arquivos_admin:
|
| 224 |
+
ext = os.path.splitext(f.name)[1].lower()
|
| 225 |
+
nome_aleatorio = f"{random.randint(1000000, 9999999)}{ext}"
|
| 226 |
+
temp_in = os.path.join(tempfile.gettempdir(), f"adm_input_{nome_aleatorio}")
|
| 227 |
+
with open(temp_in, "wb") as out:
|
| 228 |
+
out.write(f.read())
|
| 229 |
+
|
| 230 |
+
final_out = os.path.join(pasta_admin, nome_aleatorio)
|
| 231 |
+
|
| 232 |
+
# Padroniza o vídeo (igual ao seu primeiro app)
|
| 233 |
+
subprocess.run([
|
| 234 |
+
"ffmpeg", "-i", temp_in,
|
| 235 |
+
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2,fps=30",
|
| 236 |
+
"-c:v", "libx264", "-preset", "ultrafast", "-crf", "25",
|
| 237 |
+
"-y", final_out
|
| 238 |
+
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 239 |
+
|
| 240 |
+
os.remove(temp_in)
|
| 241 |
+
|
| 242 |
+
st.success("✅ Cortes enviados, padronizados e salvos com sucesso!")
|
| 243 |
+
|
| 244 |
+
# Listagem e exclusão
|
| 245 |
+
st.write("Arquivos existentes nesta categoria:")
|
| 246 |
+
try:
|
| 247 |
+
arquivos_existentes = sorted([f for f in os.listdir(pasta_admin) if f.lower().endswith(".mp4")])
|
| 248 |
+
except FileNotFoundError:
|
| 249 |
+
arquivos_existentes = []
|
| 250 |
+
|
| 251 |
+
if not arquivos_existentes:
|
| 252 |
+
st.info("Nenhum arquivo encontra
|