Open deekay2310 opened 5 years ago
Hi, First, i recomment you to combine two param to one js object, because data from client to server is in json format, im not sure weather two param can transfor correctly. secondly,you can try run your python code in debug mode to see weather your python function return the right list,and debug your js code to see weather client get the response from server.
So, my code involves recommending songs from a ML model and I have a function in Python for the same which returns a list of songs. This however is not received by the JavaScript variable and hence, it won't be printed on the console. I tried using asynchronous syntax as mentioned but no result.
//JavaScript function
async function getSimilarSongs() {
console.log("new func after doc");
var song = document.getElementById("song").value;
var artist = document.getElementById("artist").value;
var pythonList = await eel.similar_recommender(song, artist)();
console.log("----------");
console.log("similar_recommender has been called");
console.log("-----------");
console.log("recommendations are as follows:");
console.log("-----------");
console.log(pythonList);
}
#python code
import Recommenders as Recommenders
import Data as Data
import eel
eel.init("Web")
@eel.expose
def similar_recommender(user_song, user_artist):
#similarity based recommendation
sbr = Recommenders.item_similarity_recommender_py()
#model created
sbr.create(Data.train_data, 'user_id', 'song')
#taking input from user
user_input = user_song+" - "+user_artist
#converting dataframe to list
recommendation_frame = sbr.get_similar_items([user_input])
recommendation_list = list(recommendation_frame['song'])
print(recommendation_list)
return recommendation_list
eel.start("intro.html")