-
-
Save secemp9/92f5a6788f8ea0db9436df4b3e5685b5 to your computer and use it in GitHub Desktop.
forest perl script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use JSON; | |
use LWP::Simple; | |
use HTML::Strip; | |
use URI::Escape; | |
foreach my $url (map { "https://api.stackexchange.com/2.3/answers?site=stackoverflow&pagesize=100&page=$_&filter=!1zI5-*Gm0Ri9OboyAhQ5r" } (reverse 1..25)) { | |
my $json = JSON->new->decode(get($url)); | |
if (defined $json->{error_id}) { | |
warn "error id: $json->{error_id}"; | |
next; | |
} | |
foreach my $item ($json->{items}->@*) { | |
undef $thisbody; | |
$incode = 0; | |
foreach (split /\n/, HTML::Strip->new->parse($item->{body_markdown})) { | |
if (/^[~`]{3}/) { | |
$incode ^= 1; | |
next; | |
} | |
$thisbody .= "$_\n" unless (/^ / or /^\t/ or $incode); | |
} | |
next if $incode or not defined $thisbody or length $thisbody < 500; | |
my $uri = uri_escape_utf8($thisbody); | |
next unless defined $uri; | |
my $output = get("https://huggingface.co/openai-detector?$uri"); | |
next unless defined $output; | |
my $results = JSON->new->decode($output); | |
my $fakeness = sprintf "%.4f", $results->{fake_probability}; | |
next if $fakeness < 0.8; | |
my %new_json = ( | |
"user_id" => $item->{owner}->{user_id}, | |
"reputation" => $item->{owner}->{reputation}, | |
"answer_id" => $item->{answer_id}, | |
"fakeness" => $fakeness, | |
"tokens" => $results->{used_tokens} | |
); | |
print JSON->new->canonical->encode(\%new_json), "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment