Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,7 +39,7 @@ class VideoClassifier:
|
|
| 39 |
def setup_paths(self):
|
| 40 |
self.path = './results'
|
| 41 |
if os.path.exists(self.path):
|
| 42 |
-
shutil.rmtree(self.path)
|
| 43 |
os.mkdir(self.path)
|
| 44 |
|
| 45 |
def setup_gemini_model(self):
|
|
@@ -105,11 +105,8 @@ class VideoClassifier:
|
|
| 105 |
return transcript
|
| 106 |
|
| 107 |
|
| 108 |
-
def classify_video(self,video_input
|
| 109 |
-
|
| 110 |
-
self.model = model_selection
|
| 111 |
-
print(f"Model set to: {self.model}")
|
| 112 |
-
|
| 113 |
transcript=self.audio_extraction(video_input)
|
| 114 |
|
| 115 |
video = cv2.VideoCapture(video_input)
|
|
@@ -253,7 +250,16 @@ class VideoClassifier:
|
|
| 253 |
|
| 254 |
# return final_answer, first_video, second_video
|
| 255 |
return final_answer
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
def launch_interface(self):
|
| 259 |
css_code = """
|
|
@@ -264,24 +270,33 @@ class VideoClassifier:
|
|
| 264 |
--body-background-fill: #FFFFFF; /* New value */
|
| 265 |
}
|
| 266 |
"""
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
cache_examples=False, outputs=["text"],
|
| 282 |
css=css_code, title="Interactive Advertising Bureau (IAB) compliant Video-Ad classification")
|
| 283 |
-
demo.launch(debug=True)
|
| 284 |
-
|
|
|
|
|
|
|
| 285 |
def run_inference(self, video_path,model):
|
| 286 |
result = self.classify_video(video_path)
|
| 287 |
print(result)
|
|
@@ -304,3 +319,7 @@ if __name__ == "__main__":
|
|
| 304 |
vc.run_inference(args.video_path,args.model)
|
| 305 |
else:
|
| 306 |
print("Error: No video path/model provided for inference mode.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def setup_paths(self):
|
| 40 |
self.path = './results'
|
| 41 |
if os.path.exists(self.path):
|
| 42 |
+
shutil.rmtree(self.path)
|
| 43 |
os.mkdir(self.path)
|
| 44 |
|
| 45 |
def setup_gemini_model(self):
|
|
|
|
| 105 |
return transcript
|
| 106 |
|
| 107 |
|
| 108 |
+
def classify_video(self,video_input):
|
| 109 |
+
|
|
|
|
|
|
|
|
|
|
| 110 |
transcript=self.audio_extraction(video_input)
|
| 111 |
|
| 112 |
video = cv2.VideoCapture(video_input)
|
|
|
|
| 250 |
|
| 251 |
# return final_answer, first_video, second_video
|
| 252 |
return final_answer
|
| 253 |
+
|
| 254 |
+
def save_model_choice(self,model_name):
|
| 255 |
+
self.model_name = model_name
|
| 256 |
+
if self.model_name=='mistral':
|
| 257 |
+
print("Setting up Mistral model for Class Selection")
|
| 258 |
+
self.setup_mistral_model()
|
| 259 |
+
else :
|
| 260 |
+
print("Setting up Gemini model for Class Selection")
|
| 261 |
+
self.setup_gemini_model()
|
| 262 |
+
return "Model selected: " + model_name
|
| 263 |
|
| 264 |
def launch_interface(self):
|
| 265 |
css_code = """
|
|
|
|
| 270 |
--body-background-fill: #FFFFFF; /* New value */
|
| 271 |
}
|
| 272 |
"""
|
| 273 |
+
css_code += """
|
| 274 |
+
:root {
|
| 275 |
+
--body-background-fill: #000000; /* New value */
|
| 276 |
+
}
|
| 277 |
+
"""
|
| 278 |
+
|
| 279 |
+
interface_1 = gr.Interface(
|
| 280 |
+
self.save_model_choice,
|
| 281 |
+
inputs=gr.Dropdown(choices=['gemini', 'mistral'], label="Select Model", info="Default model: Gemini"),
|
| 282 |
+
# outputs=interface_1_output,
|
| 283 |
+
outputs="text"
|
| 284 |
+
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
demo = gr.Interface(fn=self.classify_video, inputs="playablevideo",allow_flagging='never', examples=[
|
| 289 |
+
os.path.join(os.path.dirname(__file__),
|
| 290 |
+
"American_football_heads_to_India_clip.mp4"),os.path.join(os.path.dirname(__file__), "PersonalFinance_clip.mp4"),
|
| 291 |
+
os.path.join(os.path.dirname(__file__), "Motorcycle_clip.mp4"),
|
| 292 |
+
os.path.join(os.path.dirname(__file__), "Spirituality_1_clip.mp4"),
|
| 293 |
+
os.path.join(os.path.dirname(__file__), "Science_clip.mp4")],
|
| 294 |
cache_examples=False, outputs=["text"],
|
| 295 |
css=css_code, title="Interactive Advertising Bureau (IAB) compliant Video-Ad classification")
|
| 296 |
+
# demo.launch(debug=True)
|
| 297 |
+
|
| 298 |
+
gr.TabbedInterface([interface_1, demo], ["Model Selection", "Video Classification"]).launch(debug=True)
|
| 299 |
+
|
| 300 |
def run_inference(self, video_path,model):
|
| 301 |
result = self.classify_video(video_path)
|
| 302 |
print(result)
|
|
|
|
| 319 |
vc.run_inference(args.video_path,args.model)
|
| 320 |
else:
|
| 321 |
print("Error: No video path/model provided for inference mode.")
|
| 322 |
+
|
| 323 |
+
#Usage
|
| 324 |
+
### python main.py --mode interface
|
| 325 |
+
### python main.py videos/Spirituality_1_clip.mp4 -n 3 --mode inference --model gemini
|