Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e5972c31a | ||
|
|
a04e6e241b |
+27
-5
@@ -9,15 +9,24 @@ my $seconds = $ENV{'SECONDS_PER_FRAME'} || 30;
|
||||
my $ollama = $ENV{'OLLAMA_URL'} || 'http://10.0.1.7:11434';
|
||||
my $api = $ENV{'API_BASE_URL'} || 'http://10.0.1.7:3000';
|
||||
my $task_count = $ENV{'TASK_COUNT'} || 1;
|
||||
my $image_count = $ENV{'IMAGE_COUNT'} || 10; # Number of images to extract from the video
|
||||
my $min_time = $ENV{'MIN_TIME'} || 5; # Minimum time between images
|
||||
my $sensitivity = 20;
|
||||
my $resolution = "672:672";
|
||||
my $model = "hf.co/Jommarn/UNSEEN_Gemma_4_26B_NSFW-GGUF:Q8_0";
|
||||
#my $model = "hf.co/Jommarn/UNSEEN_Gemma_4_26B_NSFW-GGUF:Q8_0";
|
||||
my $model = "hf.co/Jommarn/UNSEEN_Gemma_4_26B_NSFW-GGUF:Q5_K_M";
|
||||
|
||||
chdir("/tmp") || die "Unable to change directory to /tmp: $!\n";
|
||||
|
||||
my $ua = LWP::UserAgent->new;
|
||||
$ua->timeout(60);
|
||||
|
||||
if(@ARGV) {
|
||||
CheckPath($ARGV[0], {'duration' => 0});
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
for(my $i=0; $i<$task_count; $i++) {
|
||||
my $ref = GetNext();
|
||||
my $task = $ref->{'task'};
|
||||
@@ -26,7 +35,7 @@ for(my $i=0; $i<$task_count; $i++) {
|
||||
my $task_id = $task->{'id'};
|
||||
my $video_id = $video->{'id'};
|
||||
my $path = $video->{'file_path'};
|
||||
my $result = CheckPath($path);
|
||||
my $result = CheckPath($path, $video);
|
||||
|
||||
next unless $result;
|
||||
|
||||
@@ -37,12 +46,21 @@ print "Done\n";
|
||||
exit(0);
|
||||
|
||||
sub CheckPath {
|
||||
my ($path) = @_;
|
||||
my ($path, $video) = @_;
|
||||
die "File path not set\n" unless $path;
|
||||
die "File does not exist: $path\n" unless -e $path;
|
||||
|
||||
unlink(<*.png>);
|
||||
system("ffmpeg -i \"$path\" -vf fps=1/$seconds,scale=$resolution output_%04d.png");
|
||||
|
||||
# Pick a frame interval that spreads $image_count frames across the video,
|
||||
# but never more frequently than 1 frame per $min_time seconds.
|
||||
my $interval = $seconds; # fallback if duration is unknown
|
||||
if (my $duration = $video->{'duration'}) {
|
||||
my $desired = $duration / $image_count;
|
||||
$interval = ($desired > $min_time) ? $desired : $min_time;
|
||||
}
|
||||
|
||||
system("ffmpeg -i \"$path\" -vf fps=1/$interval,scale=$resolution output_%04d.png 2>&1");
|
||||
|
||||
|
||||
my $total=0;
|
||||
@@ -66,9 +84,13 @@ sub CheckPath {
|
||||
my $url = "$ollama/api/generate";
|
||||
my $res = GetRest($url, $ref);
|
||||
print "$file\t$res\n";
|
||||
#Remove thought information from the response
|
||||
$res =~ s/<\|channel>.*?<channel\|>//s;
|
||||
$res =~ s/^\s+|\s+$//g;
|
||||
$total++;
|
||||
if($res=~/yes$/i) {
|
||||
if($res=~/yes/i) {
|
||||
$yes++;
|
||||
print "\tYES\n";
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
+5
-17
@@ -196,30 +196,18 @@ sub CreateReviewTasks {
|
||||
# This avoids MariaDB's inconsistent JSON functions in SQL WHERE clauses,
|
||||
# which behave differently between CLI client and DBI connections.
|
||||
my $sth = $dbh->prepare("
|
||||
SELECT id, video_id, results
|
||||
SELECT id, video_id
|
||||
FROM tasks
|
||||
WHERE task_type='AISCAN' AND status='COMPLETED'
|
||||
WHERE task_type='AISCAN'
|
||||
AND status='COMPLETED'
|
||||
AND JSON_EXTRACT(results, '\$.verdict') = 1
|
||||
AND (SELECT 1 FROM tasks t2 WHERE t2.video_id = tasks.video_id AND t2.task_type = 'REVIEW' LIMIT 1) IS NULL
|
||||
");
|
||||
|
||||
$sth->execute();
|
||||
while (my $row = $sth->fetchrow_hashref()) {
|
||||
my $results = decode_json($row->{results});
|
||||
next unless $results && ref($results) eq 'HASH';
|
||||
next unless $results->{verdict} == 1;
|
||||
next if exists $results->{reviewed};
|
||||
|
||||
print "Creating REVIEW task for video_id: $row->{video_id}\n";
|
||||
create_task($row->{video_id}, 'REVIEW');
|
||||
|
||||
# Re-encode the whole JSON blob in Perl and update it.
|
||||
# This avoids MariaDB JSON_SET path parsing issues through DBI connections.
|
||||
$results->{reviewed} = 1;
|
||||
my $updated = encode_json($results);
|
||||
my $sth_update = $dbh->prepare(
|
||||
"UPDATE tasks SET results = ? WHERE id = ?"
|
||||
);
|
||||
$sth_update->execute($updated, $row->{id});
|
||||
$sth_update->finish();
|
||||
}
|
||||
$sth->finish();
|
||||
}
|
||||
Reference in New Issue
Block a user