After story 1
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use MIME::Base64 qw(encode_base64);
|
||||
use LWP::UserAgent;
|
||||
use JSON;
|
||||
use Data::Dumper;
|
||||
|
||||
my $seconds = 30;
|
||||
my $ollama = 'http://10.0.1.7:11434';
|
||||
my $resolution = "672:672";
|
||||
my $sensitivity = 20;
|
||||
|
||||
my $file = $ARGV[0] || die "Usage: $0 <filename>\n";
|
||||
|
||||
system("ffmpeg -i \"$file\" -vf fps=1/$seconds,scale=$resolution output_%04d.png");
|
||||
my $ua = LWP::UserAgent->new;
|
||||
$ua->timeout(60);
|
||||
|
||||
my $total=0;
|
||||
my $yes=0;
|
||||
$/ = undef;
|
||||
foreach my $file (<*.png>) {
|
||||
print "$file...\n";
|
||||
open(IN, '<:raw', $file) || die "Unable to read $file: $!\n";
|
||||
my $data = <IN>;
|
||||
close(IN);
|
||||
|
||||
my $base64 = encode_base64($data);
|
||||
$data=undef;
|
||||
|
||||
my $ref = {
|
||||
'model' => 'srizon/pixie:latest',
|
||||
'prompt' => "Are there any african american people or in this photo, whether they are shown completely or not? Please answer 'yes' or 'no' only.",
|
||||
'images' => [$base64],
|
||||
};
|
||||
|
||||
my $url = "$ollama/api/generate";
|
||||
my $res = GetRest($url, $ref);
|
||||
print "\t$res\n";
|
||||
$total++;
|
||||
if($res=~/yes/i) {
|
||||
$yes++;
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
my $percentage = ($yes*100)/$total;
|
||||
print "$yes of $total images gave yes - $percentage\n";
|
||||
if($percentage >= $sensitivity) {
|
||||
print "Probably a black dude, $percentage\n";
|
||||
} else {
|
||||
print "Probably not, $percentage\n";
|
||||
}
|
||||
|
||||
sub GetRest {
|
||||
my($url, $ref)=@_;
|
||||
my $payload = encode_json($ref);
|
||||
|
||||
my $response = $ua->post($url, 'Content_Type' => 'application/json', 'Content' => $payload);
|
||||
if($response->is_success) {
|
||||
my $content = $response->decoded_content;
|
||||
my @parts = split(/\n/, $content);
|
||||
my @refs = map { decode_json($_) } @parts;
|
||||
return join(' ', map { $_->{'response'} } @refs);
|
||||
} else {
|
||||
die "Error: " . $response->status_line;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user