Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,12 +15,21 @@ transcriptions = {}
|
|
| 15 |
def handle_transcription(username):
|
| 16 |
if request.method == 'POST':
|
| 17 |
data = request.get_json()
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
elif request.method == 'GET':
|
| 22 |
-
transcription = transcriptions.get(username,
|
| 23 |
-
return transcription
|
| 24 |
|
| 25 |
|
| 26 |
@app.route('/')
|
|
|
|
| 15 |
def handle_transcription(username):
|
| 16 |
if request.method == 'POST':
|
| 17 |
data = request.get_json()
|
| 18 |
+
new_word = data.get('transcription', '')
|
| 19 |
+
# Append new word to the user's transcription list
|
| 20 |
+
transcriptions.setdefault(username, []).append(new_word)
|
| 21 |
+
|
| 22 |
+
# Remove the 20th last word if more than 20 words are present
|
| 23 |
+
if len(transcriptions[username]) > 20:
|
| 24 |
+
transcriptions[username].pop(0)
|
| 25 |
+
|
| 26 |
+
# Join the words to form the updated transcription
|
| 27 |
+
updated_transcription = ' '.join(transcriptions[username])
|
| 28 |
+
return jsonify({"status": "success", "message": "Word added", "transcription": updated_transcription})
|
| 29 |
+
|
| 30 |
elif request.method == 'GET':
|
| 31 |
+
transcription = ' '.join(transcriptions.get(username, []))
|
| 32 |
+
return transcription if transcription else 'N/A'
|
| 33 |
|
| 34 |
|
| 35 |
@app.route('/')
|