Skip to content

Commit

Permalink
basic questions generation
Browse files Browse the repository at this point in the history
  • Loading branch information
raspberri05 committed Feb 14, 2025
1 parent 370e0be commit 70c1730
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LASTFM_API_KEY=<your_lastfm_api_key>
LASTFM_API_KEY=<your_lastfm_api_key>
GROQ_API_KEY=<your_groq_api_key>
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fastapi[standard]
requests
pandas
ruff
groq
scikit-learn
ruff
26 changes: 26 additions & 0 deletions src/app/api/ai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from dotenv import load_dotenv
from groq import Groq

load_dotenv()

GROQ_API_KEY = os.getenv("GROQ_API_KEY")
print(GROQ_API_KEY)
client = Groq(
api_key=GROQ_API_KEY,
)


def ai(df):
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Generate 3 quiz questions about the data. Only ask questions about tracks with a cluster of 1 (don't mention cluster in the questions)"
+ df.to_json(),
}
],
model="llama-3.3-70b-versatile",
)

print(chat_completion.choices[0].message.content)
6 changes: 4 additions & 2 deletions src/app/api/combine.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from ai import ai
from fetch import fetch
from model import preprocess
from ml import ml


def combine(username, period):
metadata = {"username": username, "period": period}
tracks = fetch(username, period)
preprocess(tracks)
df = ml(tracks)
ai(df)
return_data = {"metadata": metadata, "tracks": tracks}
return return_data
4 changes: 2 additions & 2 deletions src/app/api/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_top(username, period):
clean = []
counter = 0
for track in raw:
if counter >= 5:
if counter >= 20:
break
clean.append(
{
Expand All @@ -41,7 +41,7 @@ def get_info(data):
API_URL, API_KEY, track["artist"], track["name"]
)
)
if counter >= 5:
if counter >= 20:
break
temp = response.json()

Expand Down
17 changes: 17 additions & 0 deletions src/app/api/ml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pandas as pd
from sklearn.cluster import KMeans
import numpy as np


def ml(data):
df = cluster(data)
return df


def cluster(data):
df = pd.DataFrame(data)
play_counts = np.array(df["playcount"]).reshape(-1, 1)
kmeans = KMeans(n_clusters=3, random_state=42).fit(play_counts)
df["cluster"] = kmeans.labels_
print(df)
return df
7 changes: 0 additions & 7 deletions src/app/api/model.py

This file was deleted.

0 comments on commit 70c1730

Please sign in to comment.