Spaces:
Runtime error
Runtime error
File size: 1,800 Bytes
eea8ba5 fdbd33b eea8ba5 fdbd33b eea8ba5 11ef1e9 eea8ba5 f3fe982 eea8ba5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import gradio as gr
import pandas as pd
import numpy as np
import pickle
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
model = SentenceTransformer('paraphrase-distilroberta-base-v1')
# Load the dataset
data = pd.read_csv('data/Recommender_data.csv')
# Load the precomputed embeddings
with open('data/Model/tool_embeddings.pkl', 'rb') as f:
tool_embeddings = pickle.load(f)
# # Load the model from the file using pickle
# with open('data/Model/model.pkl', 'rb') as f:
# model = pickle.load(f)
# def get_sentiment(input_text):
# return sentiment(input_text)
# Define the recommendation function
def recommend(product_idea, model=model):#, model=model
# Load the pre-trained model
#model = SentenceTransformer('paraphrase-distilroberta-base-v1')
# Compute the embedding for the product idea
product_embedding = model.encode([product_idea])
# Compute the cosine similarity between the product idea vector and all tool vectors
cosine_sim_product = cosine_similarity(product_embedding, tool_embeddings)
# Sort the results in descending order and get the indices of the most similar tools
indices = np.argsort(cosine_sim_product)[0][::-1]
# Return the top 5 most similar tools
recommendations = {data.iloc[indices[i]]['Tools']: {"Description":data.iloc[indices[i]]['Description'],"URL":data.iloc[indices[i]]['URL'],"Logo":data.iloc[indices[i]]['Logo']} for i in range(4)}
return recommendations
iface = gr.Interface(fn = recommend,
inputs = "text",
outputs = ['text'],
title = 'OHA',
description="Get OHA Recomandation for the given input")
iface.launch(inline = False) |