Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -12,15 +12,12 @@ tqdm.pandas()
|
|
| 12 |
api = HfApi()
|
| 13 |
token = os.getenv("token") # Das Token wird aus den Hugging Face Secrets abgerufen
|
| 14 |
tokenread = os.getenv("tokenread")
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
if token is None:
|
| 18 |
-
raise ValueError("Hugging Face API-Token ist nicht gesetzt.")
|
| 19 |
|
| 20 |
-
# Klonen Sie das Repository (dies wird in Ihrem Space ausgeführt)
|
| 21 |
-
repo = Repository(local_dir="SpotifyHitPrediction", clone_from="Add1E/SpotifyHitPrediction")
|
| 22 |
|
| 23 |
-
def predict_popularity(features,
|
| 24 |
predictions = [None] * 2
|
| 25 |
predictions[0], predictions[1] = rf_model.predict([features]), model.predict([features])
|
| 26 |
addToCsvAndTrain(trainset)
|
|
@@ -29,18 +26,20 @@ def predict_popularity(features, trainset):
|
|
| 29 |
|
| 30 |
def addToCsvAndTrain(trainset):
|
| 31 |
trainset = [
|
| 32 |
-
[trainset[0],trainset[1],trainset[2],trainset[3],trainset[4],trainset[5],trainset[6],trainset[7],
|
| 33 |
-
trainset[8],trainset[9],trainset[10],trainset[11],trainset[12],trainset[13]
|
| 34 |
]
|
| 35 |
]
|
| 36 |
neues_df = pd.DataFrame(trainset, columns= data.columns)
|
| 37 |
df = pd.concat([data, neues_df], ignore_index=True)
|
| 38 |
-
df.to_csv('top50.csv', index=False)
|
| 39 |
-
repo.git_add('top50.csv')
|
| 40 |
repo.git_commit("Add top50.csv")
|
| 41 |
repo.git_push()
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
| 44 |
data = pd.read_csv('top50.csv', encoding='ISO-8859-1')
|
| 45 |
print(data.head())
|
| 46 |
|
|
|
|
| 12 |
api = HfApi()
|
| 13 |
token = os.getenv("token") # Das Token wird aus den Hugging Face Secrets abgerufen
|
| 14 |
tokenread = os.getenv("tokenread")
|
| 15 |
+
localdir = "SpotifyHitPrediction"
|
| 16 |
|
| 17 |
+
repo = Repository(local_dir=localdir, clone_from="https://huggingface.co/spaces/Add1E/SpotifyHitPrediction", token=token)
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
def predict_popularity(features,trainset):
|
| 21 |
predictions = [None] * 2
|
| 22 |
predictions[0], predictions[1] = rf_model.predict([features]), model.predict([features])
|
| 23 |
addToCsvAndTrain(trainset)
|
|
|
|
| 26 |
|
| 27 |
def addToCsvAndTrain(trainset):
|
| 28 |
trainset = [
|
| 29 |
+
[trainset[0], trainset[1], trainset[2], trainset[3], trainset[4], trainset[5], trainset[6], trainset[7],
|
| 30 |
+
trainset[8], trainset[9], trainset[10], trainset[11], trainset[12], trainset[13]
|
| 31 |
]
|
| 32 |
]
|
| 33 |
neues_df = pd.DataFrame(trainset, columns= data.columns)
|
| 34 |
df = pd.concat([data, neues_df], ignore_index=True)
|
| 35 |
+
df.to_csv(f'{localdir}/top50.csv', index=False)
|
| 36 |
+
repo.git_add(os.path.abspath(f'{localdir}/top50.csv'))
|
| 37 |
repo.git_commit("Add top50.csv")
|
| 38 |
repo.git_push()
|
| 39 |
|
| 40 |
|
| 41 |
+
|
| 42 |
+
|
| 43 |
data = pd.read_csv('top50.csv', encoding='ISO-8859-1')
|
| 44 |
print(data.head())
|
| 45 |
|