Mudrock10 commited on
Commit
816bd02
·
verified ·
1 Parent(s): b7fbce7

Upload streamlit_app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. streamlit_app.py +231 -0
streamlit_app.py ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import tempfile
4
+ import time
5
+ from datetime import timedelta
6
+ import pandas as pd
7
+ import numpy as np
8
+ from typing import Optional, Tuple, List
9
+ import plotly.graph_objects as go
10
+ from utils import (
11
+ process_video_upload,
12
+ extract_video_info,
13
+ create_timeline_figure,
14
+ apply_editing_effects,
15
+ export_video
16
+ )
17
+
18
+ # Set page config
19
+ st.set_page_config(
20
+ page_title="VideoCoF - Unified Video Editing",
21
+ page_icon="🎥",
22
+ layout="wide",
23
+ initial_sidebar_state="expanded"
24
+ )
25
+
26
+ # Custom CSS for modern styling
27
+ st.markdown("""
28
+ <style>
29
+ .main-header {
30
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
31
+ padding: 2rem;
32
+ border-radius: 10px;
33
+ margin-bottom: 2rem;
34
+ color: white;
35
+ }
36
+ .stButton>button {
37
+ background-color: #667eea;
38
+ color: white;
39
+ border-radius: 5px;
40
+ border: none;
41
+ padding: 0.5rem 1rem;
42
+ transition: all 0.3s;
43
+ }
44
+ .stButton>button:hover {
45
+ background-color: #5a67d8;
46
+ transform: translateY(-1px);
47
+ }
48
+ .sidebar .sidebar-content {
49
+ background-color: #f8f9fa;
50
+ }
51
+ .video-container {
52
+ border-radius: 10px;
53
+ overflow: hidden;
54
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
55
+ }
56
+ .timeline-container {
57
+ background-color: #ffffff;
58
+ border-radius: 10px;
59
+ padding: 1rem;
60
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
61
+ }
62
+ </style>
63
+ """)
64
+
65
+ # Header with anycoder link
66
+ st.markdown("""
67
+ <div class="main-header">
68
+ <h1>🎥 VideoCoF</h1>
69
+ <p style="font-size: 1.2rem; margin: 0;">Unified Video Editing with Temporal Reasoner</p>
70
+ <div style="margin-top: 1rem;">
71
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: white; text-decoration: underline;">
72
+ Built with anycoder
73
+ </a>
74
+ </div>
75
+ </div>
76
+ """, unsafe_allow_html=True)
77
+
78
+ # Initialize session state
79
+ if 'video_file' not in st.session_state:
80
+ st.session_state.video_file = None
81
+ if 'video_info' not in st.session_state:
82
+ st.session_state.video_info = None
83
+ if 'edited_video' not in st.session_state:
84
+ st.session_state.edited_video = None
85
+ if 'timeline_data' not in st.session_state:
86
+ st.session_state.timeline_data = None
87
+ if 'is_processing' not in st.session_state:
88
+ st.session_state.is_processing = False
89
+
90
+ # Sidebar for controls
91
+ with st.sidebar:
92
+ st.header("🎛️ Controls")
93
+
94
+ # Video upload section
95
+ st.subheader("Upload Video")
96
+ uploaded_file = st.file_uploader(
97
+ "Choose a video file",
98
+ type=["mp4", "avi", "mov", "mkv"],
99
+ help="Supported formats: MP4, AVI, MOV, MKV"
100
+ )
101
+
102
+ if uploaded_file and not st.session_state.is_processing:
103
+ if st.button("Load Video", type="primary"):
104
+ st.session_state.is_processing = True
105
+ with st.spinner("Processing video..."):
106
+ # Process the uploaded video
107
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4')
108
+ temp_file.write(uploaded_file.read())
109
+ temp_file.close()
110
+
111
+ # Extract video info
112
+ video_info = extract_video_info(temp_file.name)
113
+ st.session_state.video_info = video_info
114
+
115
+ # Create timeline data
116
+ st.session_state.timeline_data = create_timeline_figure(video_info)
117
+
118
+ # Store video file
119
+ st.session_state.video_file = temp_file.name
120
+
121
+ # Clean up
122
+ os.unlink(temp_file.name)
123
+ st.session_state.is_processing = False
124
+ st.rerun()
125
+
126
+ # Main content area
127
+ if st.session_state.video_file:
128
+ # Video player section
129
+ st.subheader("🎬 Video Player")
130
+ col1, col2 = st.columns([3, 1])
131
+
132
+ with col1:
133
+ st.video(st.session_state.video_file)
134
+
135
+ with col2:
136
+ if st.session_state.video_info:
137
+ st.metric("Duration", f"{st.session_state.video_info['duration']:.2f}s")
138
+ st.metric("Resolution", f"{st.session_state.video_info['width']}×{st.session_state.video_info['height']}")
139
+ st.metric("FPS", f"{st.session_state.video_info['fps']}")
140
+
141
+ # Timeline section
142
+ st.subheader("⏱️ Timeline Editor")
143
+ if st.session_state.timeline_data:
144
+ st.plotly_chart(st.session_state.timeline_data, use_container_width=True)
145
+
146
+ # Editing controls
147
+ st.subheader("✂️ Editing Tools")
148
+ editing_tabs = st.tabs(["Trim", "Effects", "Filters", "Speed"])
149
+
150
+ with editing_tabs[0]: # Trim tab
151
+ col1, col2 = st.columns(2)
152
+ with col1:
153
+ start_time = st.slider(
154
+ "Start Time",
155
+ 0.0,
156
+ st.session_state.video_info['duration'],
157
+ 0.0,
158
+ step=0.1,
159
+ help="Set the start time of the video segment"
160
+ )
161
+ with col2:
162
+ end_time = st.slider(
163
+ "End Time",
164
+ 0.0,
165
+ st.session_state.video_info['duration'],
166
+ st.session_state.video_info['duration'],
167
+ step=0.1,
168
+ help="Set the end time of the video segment"
169
+ )
170
+
171
+ with editing_tabs[1]: # Effects tab
172
+ effects = st.multiselect(
173
+ "Apply Effects",
174
+ ["Fade In", "Fade Out", "Crossfade", "Blur", "Sharpen"],
175
+ help="Select effects to apply to the video"
176
+ )
177
+
178
+ with editing_tabs[2]: # Filters tab
179
+ filters = st.selectbox(
180
+ "Video Filter",
181
+ ["None", "Grayscale", "Sepia", "Vintage", "Cool", "Warm"],
182
+ help="Apply a visual filter to the video"
183
+ )
184
+
185
+ with editing_tabs[3]: # Speed tab
186
+ speed = st.slider(
187
+ "Playback Speed",
188
+ 0.25,
189
+ 2.0,
190
+ 1.0,
191
+ step=0.25,
192
+ help="Adjust the playback speed of the video"
193
+ )
194
+
195
+ # Apply edits button
196
+ if st.button("Apply Edits", type="primary"):
197
+ with st.spinner("Applying edits..."):
198
+ st.session_state.edited_video = apply_editing_effects(
199
+ st.session_state.video_file,
200
+ start_time,
201
+ end_time,
202
+ effects,
203
+ filters,
204
+ speed
205
+ )
206
+ st.success("Edits applied successfully!")
207
+
208
+ # Export section
209
+ st.subheader("💾 Export Options")
210
+ export_format = st.selectbox(
211
+ "Export Format",
212
+ ["MP4", "AVI", "MOV"],
213
+ help="Choose the output format for your edited video"
214
+ )
215
+
216
+ if st.session_state.edited_video:
217
+ col1, col2 = st.columns([1, 1])
218
+ with col1:
219
+ if st.button("Download Edited Video"):
220
+ with open(st.session_state.edited_video, "rb") as file:
221
+ st.download_button(
222
+ label="Download",
223
+ data=file,
224
+ file_name=f"edited_video.{export_format.lower()}",
225
+ mime=f"video/{export_format.lower()}"
226
+ )
227
+ with col2:
228
+ if st.button("Export to Cloud"):
229
+ st.info("Cloud export functionality coming soon!")
230
+ else:
231
+ st.info("📁 Please upload a video file to get started with VideoCoF!")