Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified .DS_Store
Binary file not shown.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
# In our intermediate project we aimed to create a set of graphs indentifying key trends within our dataset as well as a gameplay that allows the user to input their choices in different attributes (ex. liveliness, energy, danceability, etc.) and the program will offer the user five songs that have matching outputs. This project not only has many implications for helping in the field of AI music, but offers some unique prospectives for the viewers. Additionally the program requires extensive use of databases to work. We were able to successfully create the set of graphs and design the website.
To run clone the repository and in one terminal run
uvicorn backend.main:app --reload
Second terminal for the frontend run
npm run dev
There might be libary issues which might need to be installed either using homebrew or pip.
Such as:
pip install kagglehub
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
Binary file modified backend/__pycache__/main.cpython-312.pyc
Binary file not shown.
Binary file modified backend/__pycache__/main.cpython-313.pyc
Binary file not shown.
98 changes: 96 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,115 @@
from fastapi import FastAPI
import csv
from fastapi.middleware.cors import CORSMiddleware
import kagglehub
from fastapi.responses import JSONResponse
import os
import shutil

song_features = {}
app = FastAPI()

# Allow frontend access
song_features = {}

app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Adjust in production
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

def copy_file(source, destination):
try:
shutil.copy(source, destination)
print(f"File copied from {source} to {destination}")
except Exception as e:
print(f"Error: {e}")

def reduce_csv_file_inplace(input_file, num_lines):
try:
with open(input_file, 'r+', newline='', encoding='utf-8') as file:
lines = file.readlines()
if len(lines) > num_lines:
file.seek(0)
file.writelines(lines[:num_lines])
file.truncate()
else:
print("The CSV file has fewer than 500 lines, no truncation needed.")
except Exception as e:
print(f"Error: {e}")

@app.get("/api/download_dataset")
async def download_dataset():
try:
folder_path = 'data'
if os.path.exists(folder_path):
shutil.rmtree(folder_path)
os.makedirs(folder_path, exist_ok=True)
temp_path = kagglehub.dataset_download("amitanshjoshi/spotify-1million-tracks")
filename = os.path.basename(temp_path)
final_path = os.path.join(folder_path, filename)
shutil.move(temp_path, final_path)
input_file = 'data/1/spotify_data.csv'
reduce_csv_file_inplace(input_file, 1000)
parseData(input_file)
except Exception as e:
return JSONResponse(status_code=400, content={"message": str(e)})

@app.get("/api/message")
def get_message():
return {"message": "Hello, World!"}

@app.get("/api/data")
def pass_value():
return song_features

if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)

default_template = {
"artist_name": None,
"track_name": None,
"track_id": None,
"popularity": None,
"year": None,
"genre": None,
"danceability": None,
"energy": None,
"key": None,
"loudness": None,
"mode": None,
"speechiness": None,
"acousticness": None,
"instrumentalness": None,
"liveness": None,
"valence": None,
"tempo": None,
"duration_ms": None,
"time_signature": None
}

def parseData(inputfile):
with open(inputfile, newline="", encoding="utf-8") as file:
reader = csv.DictReader(file)
i = 1
for row in reader:
track_id = i
song_features[track_id] = default_template.copy()

song_features[track_id]["artist_name"] = row.get("artist_name")
song_features[track_id]["track_name"] = row.get("track_name")
song_features[track_id]["popularity"] = int(row.get("popularity", 0))/10
song_features[track_id]["key"] = int(row.get("key"))
song_features[track_id]["year"] = int(row.get("year", 0))
song_features[track_id]["danceability"] = float(row.get("danceability", 0.0))*10
song_features[track_id]["energy"] = float(row.get("energy", 0.0))*10
song_features[track_id]["loudness"] = float(row.get("loudness", -60.0))/2
song_features[track_id]["instrumentalness"] = float(row.get("instrumentalness", 0.0))*10
song_features[track_id]["liveness"] = float(row.get("liveness", 0.0))*10
song_features[track_id]["valence"] = float(row.get("valence", 0.0))*10
song_features[track_id]["tempo"] = float(row.get("tempo", 0))/20
song_features[track_id]["duration_ms"] = int(row.get("duration_ms", 0)) // 40000
song_features[track_id]["time_signature"] = int(row.get("time_signature", 0))
i+=1
Loading