Spaces:
Sleeping
Sleeping
from app import app | |
from flask import request, jsonify | |
CONFIG = { | |
"day": { | |
"eps": 0.2, | |
"min_samples": 5 | |
}, | |
"week": { | |
"eps": 0.15, | |
"min_samples": 5 | |
}, | |
"month": { | |
"eps": 0.15, | |
"min_samples": 5, | |
}, | |
} | |
def cluster(): | |
data = request.get_json() | |
embeddings = data['embeddings'] | |
duration = data['duration'] | |
from sklearn.cluster import DBSCAN | |
import numpy as np | |
try: | |
dbscan = DBSCAN(eps=CONFIG[duration]['eps'], min_samples=CONFIG[duration]['min_samples'], metric='cosine', n_jobs=-1) | |
embeddings_array = np.array(embeddings) | |
labels = dbscan.fit_predict(embeddings_array) | |
labels = labels.tolist() | |
return jsonify({'labels': labels}) | |
except Exception as e: | |
return jsonify({'error': str(e)}) | |