Skip to content

UI ml #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4ef2a97
trial commit message
stllazhn Mar 11, 2025
41d8961
remove 4300env1
stllazhn Mar 11, 2025
9c5de42
set up the basic UI for the Search Engine
danish-safdariyan Mar 18, 2025
b74aca6
Initial NLP setup - Stella
stllazhn Mar 18, 2025
b095433
Merge branchesMerge branch 'master' of https://github.com/stllazhn/43…
stllazhn Mar 18, 2025
346a3e5
add more NLP stuff - Stella
stllazhn Mar 19, 2025
1e3cb6f
add implementation comment
stllazhn Mar 19, 2025
ce34eca
ml.py added version
danish-safdariyan Mar 19, 2025
2fe236d
streamlit fixed
stllazhn Mar 20, 2025
87054d4
retrying to add streamlit changes and flask changes
danish-safdariyan Mar 20, 2025
b85e1ee
Merge branch 'master' into UI-ML
Andisha2004 Mar 20, 2025
712a73a
Merge pull request #1 from stllazhn/UI-ML
Andisha2004 Mar 20, 2025
835dc22
basic version of UI using provided html and css
danish-safdariyan Mar 21, 2025
4ff5f68
Merge pull request #2 from stllazhn/UI-ML
danish-safdariyan Mar 21, 2025
958e76b
updated UI
danish-safdariyan Mar 21, 2025
93e2361
Merge pull request #3 from stllazhn/UI-ML
danish-safdariyan Mar 21, 2025
fd09717
changes in requirements.txt
danish-safdariyan Mar 21, 2025
f9b0ea3
Merge pull request #4 from stllazhn/UI-ML
danish-safdariyan Mar 21, 2025
1e81508
adding fsspec in requirements.txt
danish-safdariyan Mar 21, 2025
8b44db3
Merge pull request #5 from stllazhn/UI-ML
danish-safdariyan Mar 21, 2025
177f1c3
downloaded the huggingface dataset
Liu-Brianna Mar 21, 2025
5ad6828
changed linking
Liu-Brianna Mar 21, 2025
2489f24
add debugging statements
Liu-Brianna Mar 21, 2025
440f437
fixing loading csv
stllazhn Mar 21, 2025
1a027f6
changed path in ml.py
Liu-Brianna Mar 21, 2025
7b8120e
fixing csv not read issue
stllazhn Mar 21, 2025
945fa05
changed path again
Liu-Brianna Mar 21, 2025
e5fa766
Merge branch 'master' of https://github.com/stllazhn/4300-JSON-wander…
stllazhn Mar 21, 2025
a693dc1
try to change API call
Liu-Brianna Mar 21, 2025
139057b
made to GET methods
Liu-Brianna Mar 21, 2025
ee8c13b
changing url in base.html
stllazhn Mar 22, 2025
3159671
base html url change
stllazhn Mar 22, 2025
9f7cdf8
changed path to rel
Liu-Brianna Mar 22, 2025
91931a5
tried to make work
Liu-Brianna Mar 22, 2025
37e58ab
tried debugging
Liu-Brianna Mar 22, 2025
ae86840
xsv
stllazhn Mar 22, 2025
75e02eb
changes on app.py
danish-safdariyan Mar 22, 2025
a321556
adding the mini datasets again
danish-safdariyan Mar 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
import json
import os
from flask import Flask, render_template, request
from flask import Flask, render_template, request, jsonify
from flask_cors import CORS
from helpers.MySQLDatabaseHandler import MySQLDatabaseHandler
import pandas as pd
import ml

# ROOT_PATH for linking with all your files.
# Feel free to use a config.py or settings.py with a global export variable
os.environ['ROOT_PATH'] = os.path.abspath(os.path.join("..",os.curdir))
# ROOT_PATH for linking with all your files.
os.environ['ROOT_PATH'] = os.path.abspath(os.path.join("..", os.curdir))

# Get the directory of the current script
current_directory = os.path.dirname(os.path.abspath(__file__))

# Specify the path to the JSON file relative to the current script
json_file_path = os.path.join(current_directory, 'init.json')

# Assuming your JSON data is stored in a file named 'init.json'
with open(json_file_path, 'r') as file:
data = json.load(file)
episodes_df = pd.DataFrame(data['episodes'])
reviews_df = pd.DataFrame(data['reviews'])

app = Flask(__name__)
CORS(app)

# Sample search using json with pandas
def json_search(query):
matches = []
merged_df = pd.merge(episodes_df, reviews_df, left_on='id', right_on='id', how='inner')
matches = merged_df[merged_df['title'].str.lower().str.contains(query.lower())]
matches_filtered = matches[['title', 'descr', 'imdb_rating']]
matches_filtered_json = matches_filtered.to_json(orient='records')
return matches_filtered_json

@app.route("/")
def home():
return render_template('base.html',title="sample html")

@app.route("/episodes")
def episodes_search():
text = request.args.get("title")
return json_search(text)

if 'DB_NAME' not in os.environ:
app.run(debug=True,host="0.0.0.0",port=5000)
return render_template('base.html', title="WanderingMelody")

@app.route("/recommendations")
def recommendations():
mood = request.args.get("mood")
location = request.args.get("location")
age = request.args.get("age", default=18, type=int) # default age is 18 if not provided
genre = request.args.get("genre")

# Validate inputs (at least mood or genre should be provided)
if not mood:
return jsonify({"error": "Please provide at least a mood description or a genre."}), 400

# Preprocess the lyric data and build necessary indices (using ML functions)
dict_of_lyrics = ml.lyric_df[['text']].to_dict(orient="index")
cleaned_tokenized_lyrics = ml.tokenize_lyrics(dict_of_lyrics, ml.tokenize)
cleaned_tokenized_lyrics = ml.remove_stop_words(ml.custom_stopwords, cleaned_tokenized_lyrics)
inverted_index = ml.build_inverted_index(cleaned_tokenized_lyrics)
clean_song_count = ml.compute_idf(inverted_index, len(cleaned_tokenized_lyrics))

# Call the recommendation function from ml.py
recommended_songs, synonyms = ml.recommend_songs(mood, cleaned_tokenized_lyrics, clean_song_count)

if not recommended_songs:
return jsonify([])

# Get song details (e.g., title, artist, album, genre, rating)
song_details = ml.get_song_details(recommended_songs)

return jsonify(song_details)

if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5000)
Loading