Spaces:
Runtime error
Runtime error
File size: 4,025 Bytes
f7e17ff |
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import streamlit as st
import numpy as np
from video_processing import enhance_video
from config import EXAMPLES
st.set_page_config(
page_title="Сверточный Видоусилитель",
page_icon="🎬",
layout="wide"
)
def main():
st.title("🎬 Сверточный Видоусилитель")
if 'current_filter' not in st.session_state:
st.session_state.current_filter = "Повышение резкости"
st.session_state.kernel = EXAMPLES["Повышение резкости"]
# Секция загрузки файла
uploaded_file = st.file_uploader("📤 Загрузите видео файл", type=["mp4", "avi", "mov"])
# Панель управления фильтрами
with st.sidebar:
st.header("⚙ Настройки свертки")
# Отображение текущего фильтра
st.markdown(f"**Активный фильтр:** `{st.session_state.current_filter}`")
kernel_input = st.text_input(
"Матрица 3x3 (9 чисел через запятую):",
value=", ".join(map(str, st.session_state.kernel.flatten())),
help="Пример: -1, -1, -1, -1, 9, -1, -1, -1, -1",
key="kernel_input"
)
st.subheader("📚 Пресеты фильтров")
cols = st.columns(2)
for idx, (name, example) in enumerate(EXAMPLES.items()):
with cols[idx % 2]:
is_active = name == st.session_state.current_filter
btn_label = f"✅ {name}" if is_active else f"⚙️ {name}"
if st.button(
btn_label,
help=f"Матрица: {example.tolist()}",
use_container_width=True
):
st.session_state.current_filter = name
st.session_state.kernel = example
st.rerun()
if uploaded_file:
if st.button("🚀 ПРИМЕНИТЬ СВЕРТОЧНЫЙ ФИЛЬТР", use_container_width=True, type="primary"):
try:
if not kernel_input.strip():
st.error("❌ Выберите фильтр или введите свою матрицу!")
return
kernel_values = [float(x.strip()) for x in kernel_input.split(',')]
if len(kernel_values) != 9:
st.error("❌ Требуется ровно 9 значений через запятую!")
return
if all(abs(x) < 0.0001 for x in kernel_values):
st.error("❌ Матрица не может быть нулевой!")
return
kernel = np.array(kernel_values).reshape(3, 3)
st.session_state.kernel = kernel
st.session_state.current_filter = "Пользовательский"
with st.spinner("🔎 Применяем сверточный фильтр..."):
processed_path = enhance_video(uploaded_file, kernel)
col1, col2 = st.columns(2)
with col1:
st.subheader("Исходное видео")
st.video(uploaded_file)
with col2:
st.subheader("Результат обработки")
st.video(processed_path)
with open(processed_path, "rb") as f:
st.download_button(
label="💾 Скачать результат",
data=f,
file_name="conv_video.mp4",
mime="video/mp4",
use_container_width=True
)
except Exception as e:
st.error(f"⚠️ Критическая ошибка: {str(e)}")
if __name__ == "__main__":
main() |