Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -80,7 +80,7 @@ class VideoHighlightDetector:
|
|
80 |
return_tensors="pt"
|
81 |
).to(self.device)
|
82 |
|
83 |
-
outputs = self.
|
84 |
return self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
|
85 |
|
86 |
def determine_highlights(self, video_description: str, prompt_num: int = 1) -> str:
|
@@ -117,7 +117,7 @@ class VideoHighlightDetector:
|
|
117 |
return_tensors="pt"
|
118 |
).to(self.device)
|
119 |
|
120 |
-
outputs = self.
|
121 |
return self.processor.decode(outputs[0], skip_special_tokens=True).split("Assistant: ")[1]
|
122 |
|
123 |
def process_segment(self, video_path: str, highlight_types: str) -> bool:
|
@@ -147,7 +147,7 @@ class VideoHighlightDetector:
|
|
147 |
return_tensors="pt"
|
148 |
).to(self.device)
|
149 |
|
150 |
-
outputs = self.
|
151 |
response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
|
152 |
print(f"Segment response {response}")
|
153 |
return "yes" in response
|
@@ -194,6 +194,10 @@ class VideoHighlightDetector:
|
|
194 |
logger.info(f"Running ffmpeg command: {' '.join(cmd)}")
|
195 |
subprocess.run(cmd, check=True)
|
196 |
|
|
|
|
|
|
|
|
|
197 |
def create_ui(examples_path: str, model_path: str):
|
198 |
examples_data = load_examples(examples_path)
|
199 |
|
|
|
80 |
return_tensors="pt"
|
81 |
).to(self.device)
|
82 |
|
83 |
+
outputs = self._generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.7)
|
84 |
return self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
|
85 |
|
86 |
def determine_highlights(self, video_description: str, prompt_num: int = 1) -> str:
|
|
|
117 |
return_tensors="pt"
|
118 |
).to(self.device)
|
119 |
|
120 |
+
outputs = self._generate(**inputs, max_new_tokens=256, do_sample=True, temperature=0.7)
|
121 |
return self.processor.decode(outputs[0], skip_special_tokens=True).split("Assistant: ")[1]
|
122 |
|
123 |
def process_segment(self, video_path: str, highlight_types: str) -> bool:
|
|
|
147 |
return_tensors="pt"
|
148 |
).to(self.device)
|
149 |
|
150 |
+
outputs = self._generate(**inputs, max_new_tokens=64, do_sample=False)
|
151 |
response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
|
152 |
print(f"Segment response {response}")
|
153 |
return "yes" in response
|
|
|
194 |
logger.info(f"Running ffmpeg command: {' '.join(cmd)}")
|
195 |
subprocess.run(cmd, check=True)
|
196 |
|
197 |
+
def _generate(self, **kwargs):
|
198 |
+
with autocast(device_type="cuda", dtype=torch.float16):
|
199 |
+
return self.model.generate(**kwargs)
|
200 |
+
|
201 |
def create_ui(examples_path: str, model_path: str):
|
202 |
examples_data = load_examples(examples_path)
|
203 |
|