Shritam commited on
Commit
eea8ba5
·
1 Parent(s): aff15c2

created app.py

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