Spaces:
Build error
Build error
Miquel Farre
commited on
Commit
·
8323202
1
Parent(s):
0cb8d8c
app.py
CHANGED
|
@@ -95,91 +95,91 @@ def create_ui(examples_path: str):
|
|
| 95 |
@spaces.GPU
|
| 96 |
def on_process(video):
|
| 97 |
if not video:
|
| 98 |
-
yield
|
| 99 |
-
"
|
| 100 |
-
"
|
| 101 |
-
"
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
return
|
| 106 |
|
| 107 |
try:
|
| 108 |
duration = get_video_duration_seconds(video)
|
| 109 |
if duration > 1200: # 20 minutes
|
| 110 |
-
yield
|
| 111 |
-
"
|
| 112 |
-
"
|
| 113 |
-
"
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
return
|
| 118 |
|
| 119 |
# Make accordion visible as soon as processing starts
|
| 120 |
-
yield
|
| 121 |
-
"
|
| 122 |
-
"
|
| 123 |
-
"
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
|
| 128 |
model, processor = load_model()
|
| 129 |
detector = BatchedVideoHighlightDetector(model, processor, batch_size=8)
|
| 130 |
|
| 131 |
-
yield
|
| 132 |
-
"
|
| 133 |
-
"
|
| 134 |
-
"
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
|
| 139 |
video_desc = detector.analyze_video_content(video)
|
| 140 |
formatted_desc = f"#Summary: {video_desc[:500] + '...' if len(video_desc) > 500 else video_desc}"
|
| 141 |
|
| 142 |
# Update description as soon as it's available
|
| 143 |
-
yield
|
| 144 |
-
"
|
| 145 |
-
|
| 146 |
-
"
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
|
| 151 |
highlights = detector.determine_highlights(video_desc)
|
| 152 |
formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
|
| 153 |
|
| 154 |
# Update highlights as soon as they're available
|
| 155 |
-
yield
|
| 156 |
-
"
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
|
| 163 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
|
| 164 |
temp_output = tmp_file.name
|
| 165 |
detector.create_highlight_video(video, temp_output)
|
| 166 |
|
| 167 |
-
yield
|
| 168 |
-
"
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
|
| 175 |
except Exception as e:
|
| 176 |
-
yield
|
| 177 |
-
|
| 178 |
-
"
|
| 179 |
-
"
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
|
| 184 |
process_btn.click(
|
| 185 |
on_process,
|
|
@@ -191,7 +191,7 @@ def create_ui(examples_path: str):
|
|
| 191 |
output_video,
|
| 192 |
analysis_accordion
|
| 193 |
],
|
| 194 |
-
queue=True,
|
| 195 |
)
|
| 196 |
|
| 197 |
return app
|
|
|
|
| 95 |
@spaces.GPU
|
| 96 |
def on_process(video):
|
| 97 |
if not video:
|
| 98 |
+
yield [
|
| 99 |
+
"Please upload a video", # status
|
| 100 |
+
"", # video_description
|
| 101 |
+
"", # highlight_types
|
| 102 |
+
gr.update(visible=False), # output_video
|
| 103 |
+
gr.update(visible=False) # analysis_accordion
|
| 104 |
+
]
|
| 105 |
return
|
| 106 |
|
| 107 |
try:
|
| 108 |
duration = get_video_duration_seconds(video)
|
| 109 |
if duration > 1200: # 20 minutes
|
| 110 |
+
yield [
|
| 111 |
+
"Video must be shorter than 20 minutes",
|
| 112 |
+
"",
|
| 113 |
+
"",
|
| 114 |
+
gr.update(visible=False),
|
| 115 |
+
gr.update(visible=False)
|
| 116 |
+
]
|
| 117 |
return
|
| 118 |
|
| 119 |
# Make accordion visible as soon as processing starts
|
| 120 |
+
yield [
|
| 121 |
+
"Loading model...",
|
| 122 |
+
"",
|
| 123 |
+
"",
|
| 124 |
+
gr.update(visible=False),
|
| 125 |
+
gr.update(visible=True)
|
| 126 |
+
]
|
| 127 |
|
| 128 |
model, processor = load_model()
|
| 129 |
detector = BatchedVideoHighlightDetector(model, processor, batch_size=8)
|
| 130 |
|
| 131 |
+
yield [
|
| 132 |
+
"Analyzing video content...",
|
| 133 |
+
"",
|
| 134 |
+
"",
|
| 135 |
+
gr.update(visible=False),
|
| 136 |
+
gr.update(visible=True)
|
| 137 |
+
]
|
| 138 |
|
| 139 |
video_desc = detector.analyze_video_content(video)
|
| 140 |
formatted_desc = f"#Summary: {video_desc[:500] + '...' if len(video_desc) > 500 else video_desc}"
|
| 141 |
|
| 142 |
# Update description as soon as it's available
|
| 143 |
+
yield [
|
| 144 |
+
"Determining highlight types...",
|
| 145 |
+
formatted_desc,
|
| 146 |
+
"",
|
| 147 |
+
gr.update(visible=False),
|
| 148 |
+
gr.update(visible=True)
|
| 149 |
+
]
|
| 150 |
|
| 151 |
highlights = detector.determine_highlights(video_desc)
|
| 152 |
formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
|
| 153 |
|
| 154 |
# Update highlights as soon as they're available
|
| 155 |
+
yield [
|
| 156 |
+
"Detecting and extracting highlights...",
|
| 157 |
+
formatted_desc,
|
| 158 |
+
formatted_highlights,
|
| 159 |
+
gr.update(visible=False),
|
| 160 |
+
gr.update(visible=True)
|
| 161 |
+
]
|
| 162 |
|
| 163 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
|
| 164 |
temp_output = tmp_file.name
|
| 165 |
detector.create_highlight_video(video, temp_output)
|
| 166 |
|
| 167 |
+
yield [
|
| 168 |
+
"Processing complete!",
|
| 169 |
+
formatted_desc,
|
| 170 |
+
formatted_highlights,
|
| 171 |
+
gr.update(value=temp_output, visible=True),
|
| 172 |
+
gr.update(visible=True)
|
| 173 |
+
]
|
| 174 |
|
| 175 |
except Exception as e:
|
| 176 |
+
yield [
|
| 177 |
+
f"Error processing video: {str(e)}",
|
| 178 |
+
"",
|
| 179 |
+
"",
|
| 180 |
+
gr.update(visible=False),
|
| 181 |
+
gr.update(visible=False)
|
| 182 |
+
]
|
| 183 |
|
| 184 |
process_btn.click(
|
| 185 |
on_process,
|
|
|
|
| 191 |
output_video,
|
| 192 |
analysis_accordion
|
| 193 |
],
|
| 194 |
+
queue=True,
|
| 195 |
)
|
| 196 |
|
| 197 |
return app
|