dhruthick commited on
Commit
1d48db3
·
1 Parent(s): 9b9b308

added config file for handling tokens

Browse files
Files changed (2) hide show
  1. .gitignore +2 -1
  2. app.py +9 -2
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  .DS_Store
2
  backend/.DS_Store
3
- backend/models/bert-mood-prediction-1.pt
 
 
1
  .DS_Store
2
  backend/.DS_Store
3
+ backend/models/bert-mood-prediction-1.pt
4
+ config.json
app.py CHANGED
@@ -1,6 +1,6 @@
1
  from flask import Flask, request, jsonify, send_from_directory
2
  from lyricsgenius import Genius
3
-
4
  import torch
5
  import numpy as np
6
  from transformers import BertTokenizer, BertForSequenceClassification
@@ -24,6 +24,12 @@ model = BertForSequenceClassification.from_pretrained(
24
  model.load_state_dict(torch.load('backend/models/bert-mood-prediction-1.pt', map_location=torch.device('cpu')))
25
  model.eval()
26
 
 
 
 
 
 
 
27
  def tokenize_and_format(sentences):
28
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
29
 
@@ -90,7 +96,8 @@ def predict():
90
  def get_lyrics(song_title, artist_name):
91
  # Implement the lyrics fetching logic here
92
  # This is a placeholder function
93
- token='PFl5Jdd01ayEMNqxIkuoAWnA7N9Xw9KqD9BSphLmjQ4IBrJqyaTA9CxKP2k8yJpz'
 
94
  genius = Genius(token)
95
  genius.timeout = 300
96
  try:
 
1
  from flask import Flask, request, jsonify, send_from_directory
2
  from lyricsgenius import Genius
3
+ import json
4
  import torch
5
  import numpy as np
6
  from transformers import BertTokenizer, BertForSequenceClassification
 
24
  model.load_state_dict(torch.load('backend/models/bert-mood-prediction-1.pt', map_location=torch.device('cpu')))
25
  model.eval()
26
 
27
+ # load API Token in config file
28
+ with open('config.json', 'r') as config_file:
29
+ config = json.load(config_file)
30
+
31
+
32
+
33
  def tokenize_and_format(sentences):
34
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
35
 
 
96
  def get_lyrics(song_title, artist_name):
97
  # Implement the lyrics fetching logic here
98
  # This is a placeholder function
99
+ # Get the token from the configuration
100
+ token = config.get('GENIUS_TOKEN')
101
  genius = Genius(token)
102
  genius.timeout = 300
103
  try: