Spaces:
Runtime error
Runtime error
fix bug?
#3
by WeiHan123 - opened
app.py
CHANGED
|
@@ -59,15 +59,25 @@ def authenticate(new_username, new_pw):
|
|
| 59 |
|
| 60 |
def get_user_transcripts(username):
|
| 61 |
arr = []
|
| 62 |
-
if username is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Fetch user's records
|
| 64 |
-
user_transcripts =
|
| 65 |
for trans in user_transcripts:
|
| 66 |
trans_dict = trans.to_dict()
|
| 67 |
arr.append([trans_dict['date'], trans_dict['transcription'], trans_dict['sentiment_output']])
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
return arr
|
| 72 |
|
| 73 |
def get_user_score(username):
|
|
|
|
| 59 |
|
| 60 |
def get_user_transcripts(username):
|
| 61 |
arr = []
|
| 62 |
+
if username is None:
|
| 63 |
+
# User not logged in, return null transcript
|
| 64 |
+
return ['', '', '']
|
| 65 |
+
|
| 66 |
+
# Check if the collection exists for the user
|
| 67 |
+
user_transcripts_ref = db.collection(f'Users/{username}/Transcripts')
|
| 68 |
+
if not user_transcripts_ref.get(): # Check if the collection exists
|
| 69 |
+
return arr # Return empty array if the collection doesn't exist
|
| 70 |
+
|
| 71 |
# Fetch user's records
|
| 72 |
+
user_transcripts = user_transcripts_ref.stream()
|
| 73 |
for trans in user_transcripts:
|
| 74 |
trans_dict = trans.to_dict()
|
| 75 |
arr.append([trans_dict['date'], trans_dict['transcription'], trans_dict['sentiment_output']])
|
| 76 |
+
|
| 77 |
+
# If no transcripts found, return null transcript
|
| 78 |
+
if len(arr) == 0:
|
| 79 |
+
return ['', '', '']
|
| 80 |
+
|
| 81 |
return arr
|
| 82 |
|
| 83 |
def get_user_score(username):
|