from flask import Flask, request, jsonify, Response import asyncio from hypercorn.asyncio import serve from hypercorn.config import Config import os os.environ['CURL_CA_BUNDLE'] = '' app = Flask(__name__) transcriptions = {} @app.route('/', methods=['POST', 'GET']) def handle_transcription(username): if request.method == 'POST': data = request.get_json() new_word = data.get('transcription', '') # Append new word to the user's transcription list transcriptions.setdefault(username, []).append(new_word) # Remove the 20th last word if more than 20 words are present if len(transcriptions[username]) > 1: transcriptions[username].pop(0) # Join the words to form the updated transcription updated_transcription = ' '.join(transcriptions[username]) return jsonify({"status": "success", "message": "Word added", "transcription": updated_transcription}) elif request.method == 'GET': transcription = ' '.join(transcriptions.get(username, [])) return transcription if transcription else 'N/A' @app.route('/') def home(): html_content = """ Speech to Text

Speech Recognition

""" return Response(html_content, mimetype='text/html') if __name__ == "__main__": config = Config() config.bind = ["0.0.0.0:7860"] # You can specify the host and port here asyncio.run(serve(app, config))