<commit_before>from collections import OrderedDict
import face_recognition
import os
import sqlite3
from sqlite3 import Error
import argparse
import nltk
import numpy as np
import re
import string
from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.stem.porter import PorterStemmer
from sklearn.metrics.pairwise import cosine_similarity

def get_matched_results(gender, description):
    if gender == 'M':
        all_pictures = os.listdir("profile_pictures/males")
    else:
        all_pictures = os.listdir("profile_pictures/females")
    all_pictures.pop(0)
    
    #get the feature vector of the uploaded picture.
    image_to_test = face_recognition.load_image_file("temp_upload/temp.jpg")
    image_to_test_encoding = face_recognition.face_encodings(image_to_test)[0]
    pic_dict = {}
    for picture in all_pictures:
        if gender == 'M':
            current = face_recognition.load_image_file("profile_pictures/males/"+picture)
        else:
            current = face_recognition.load_image_file("profile_pictures/females/"+picture)

        encoding = face_recognition.face_encodings(current)
        
        #compute the face distance.
        face_distance = face_recognition.face_distance(encoding, image_to_test_encoding)
        if len(face_distance) != 0:
            pic_dict[int(picture.replace('.jpg', ''))] = face_distance[0]
        print(face_distance)
        print("this is for",picture)
        
    #extract top 10 indices
    sorted_dict = OrderedDict(sorted(pic_dict.items(), key=lambda x: x[1]))
    top_indices = list(sorted_dict.keys())[:10]
    print(top_indices)
    return get_text_match(gender, description, top_indices)

def get_text_match(gender, description, top_indices):
    database = "database.db"
 
    # create a database connection
    conn = create_connection(database)
    print(top_indices)
    with conn:
        texts = []
        if(gender == 'M'):
            for index in top_indices:
                texts.append(select_male_texts(conn, index)[0][0])
        else:
            for index in top_indices:
                texts.append(select_female_texts(conn, index)[0][0])
    text_dict = {}
    current = 0
    reversed_top_indices = top_indices[::-1]
    for index in reversed_top_indices:
        text_dict[index] = sim(description, texts)[current][0]
        current = current + 1
    sorted_dict = OrderedDict(sorted(text_dict.items(), key=lambda x: x[1]))
    reranked_indices = list(sorted_dict.keys())[:10]
    reversed_indices = reranked_indices[::-1]
    return reversed_indices
    
    
def sim(description, texts):
    descriptions = []<commit_msg>remove all the printing stuff<commit_after>from collections import OrderedDict
import face_recognition
import os
import sqlite3
from sqlite3 import Error
import argparse
import nltk
import numpy as np
import re
import string
from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.stem.porter import PorterStemmer
from sklearn.metrics.pairwise import cosine_similarity

def get_matched_results(gender, description):
    if gender == 'M':
        all_pictures = os.listdir("profile_pictures/males")
    else:
        all_pictures = os.listdir("profile_pictures/females")
    all_pictures.pop(0)
    
    #get the feature vector of the uploaded picture.
    image_to_test = face_recognition.load_image_file("temp_upload/temp.jpg")
    image_to_test_encoding = face_recognition.face_encodings(image_to_test)[0]
    pic_dict = {}
    for picture in all_pictures:
        if gender == 'M':
            current = face_recognition.load_image_file("profile_pictures/males/"+picture)
        else:
            current = face_recognition.load_image_file("profile_pictures/females/"+picture)

        encoding = face_recognition.face_encodings(current)
        
        #compute the face distance.
        face_distance = face_recognition.face_distance(encoding, image_to_test_encoding)
        if len(face_distance) != 0:
            pic_dict[int(picture.replace('.jpg', ''))] = face_distance[0]
        
    #extract top 10 indices
    sorted_dict = OrderedDict(sorted(pic_dict.items(), key=lambda x: x[1]))
    top_indices = list(sorted_dict.keys())[:10]
    return get_text_match(gender, description, top_indices)

def get_text_match(gender, description, top_indices):
    database = "database.db"
 
    # create a database connection
    conn = create_connection(database)
    with conn:
        texts = []
        if(gender == 'M'):
            for index in top_indices:
                texts.append(select_male_texts(conn, index)[0][0])
        else:
            for index in top_indices:
                texts.append(select_female_texts(conn, index)[0][0])
    text_dict = {}
    current = 0
    reversed_top_indices = top_indices[::-1]
    for index in reversed_top_indices:
        text_dict[index] = sim(description, texts)[current][0]
        current = current + 1
    sorted_dict = OrderedDict(sorted(text_dict.items(), key=lambda x: x[1]))
    reranked_indices = list(sorted_dict.keys())[:10]
    reversed_indices = reranked_indices[::-1]
    return reversed_indices
    
    
def sim(description, texts):
    descriptions = []
{'fraction_non_alphanumeric': 0.09625771604938271, 'fraction_numerical': 0.008873456790123456, 'mean_word_length': 3.4278394534585823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4383618', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1586, 'n_words': 338}