Spaces:
Running
Running
| import re | |
| from flask import Flask, render_template, request | |
| from asgiref.wsgi import WsgiToAsgi | |
| app = Flask(__name__) | |
| def process_ssml_text(ssml_text): | |
| """ | |
| Process SSML text to extract content between SSML tags and format it properly. | |
| """ | |
| # Regular expression to find all textnorm tags and their content | |
| result = [] | |
| # Process each line separately | |
| lines = ssml_text.split('\n') | |
| for line in lines: | |
| # Create a new line by removing all SSML tags and just using the clean text | |
| clean_line = re.sub(r'<textnorm[^>]*>([^<]*)</textnorm>', r'\1', line) | |
| # Replace specific symbols to match the expected output | |
| clean_line = clean_line.replace('A☼M', 'A※M').replace('P☼M', 'P※M') | |
| result.append(clean_line) | |
| return '\n'.join(result) | |
| def index(): | |
| processed_text = "" | |
| input_text = "" | |
| if request.method == 'POST': | |
| input_text = request.form.get('input_text', '') | |
| processed_text = process_ssml_text(input_text) | |
| return render_template('index.html', processed_text=processed_text, input_text=input_text) | |
| if __name__ == '__main__': | |
| app.run(debug=True) | |