<commit_before>require 'open-uri'
require 'unirest'

module Cinch
  module Plugins
    class Twins
      include Cinch::Plugin

      match /(twins) (.+)/
      match /(help twins)$/, method: :help

      def execute(m, prefix, twins, links)
        urls = links.split(/[[:space:]]/)
        url = URI.encode(urls[0])
        url_2 = URI.encode(urls[1])
        response = Unirest.post "http://rekognition.com/func/api/?api_key=#{ENV['REKOGNITION_KEY']}&api_secret=#{ENV['REKOGNITION_SECRET']}&jobs=face_compare&urls=#{url}&urls_compare=#{url_2}",
          headers:{
            "X-Mashape-Key" => "#{ENV['MASHAPE_KEY']}",
            "Content-Type" => "application/x-www-form-urlencoded",
            "Accept" => "application/json"
          }
        return m.reply "sumn wrong wit ur first pic bru" if response.body['face_detection'].nil?
        return m.reply "sumn wrong wit ur 2nd pic bru" if response.body['face_detection'].size == 1
        score = response.body['face_detection'][1]['matches'].first['score'].to_f * 100
        return m.reply "same person bru. im #{score}% sure" if score == 100
        return m.reply "#{score}% is the same person. maybe twins? iono" if score > 70
        m.reply "#{score}% is the same person"
      end

      def help(m)
        m.reply 'returns a facial similarity score for two specified images'
      end

    end
  end<commit_msg>Update twins plugin with new api (aws)<commit_after>require 'aws-sdk'
require 'open-uri'

module Cinch
  module Plugins
    class Twins
      include Cinch::Plugin

      match /(twins) (.+)/
      match /(help twins)$/, method: :help

      def initialize(*args)
        super
        Aws.config.update({
          region: 'us-west-2',
          credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
        })
        @client = Aws::Rekognition::Client.new
      end

      def execute(m, prefix, twins, links)
        urls = links.split(/[[:space:]]/)
        source_url = URI.encode(urls[0])
        target_url = URI.encode(urls[1])
        begin
          resp = @client.compare_faces(
            source_image: { bytes: open(source_url).read },
            target_image: { bytes: open(target_url).read }
          )
        rescue Exception => e
          return m.reply "Error: #{e}"
        end
        score = resp['face_matches'].first.similarity.round(2)
        return m.reply "same person bru. #{score}% sure!" if score > 94.99
        return m.reply "#{score}% is the same person. maybe twins?" if score > 74.99
        m.reply "#{score}% is the same person"
      end

      def help(m)
        m.reply 'returns a facial similarity score for two specified images using aws rekognition'
      end

    end
  end
{'fraction_non_alphanumeric': 0.13666180758017493, 'fraction_numerical': 0.009839650145772596, 'mean_word_length': 2.4398496240601504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6233250', 'n_tokens_mistral': 896, 'n_tokens_neox': 852, 'n_words': 225}