Spaces:
Running
Running
Commit
·
aef9afa
1
Parent(s):
0824a9a
feat: Add legacy SSML processing mode, UI selector, and editor settings
Browse files- .vscode/settings.json +5 -0
- app.py +39 -0
- templates/index.html +39 -1
- templates/ssml-old.html +0 -0
.vscode/settings.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"python-envs.defaultEnvManager": "ms-python.python:conda",
|
| 3 |
+
"python-envs.defaultPackageManager": "ms-python.python:conda",
|
| 4 |
+
"python-envs.pythonProjects": []
|
| 5 |
+
}
|
app.py
CHANGED
|
@@ -26,6 +26,34 @@ def process_ssml_text(ssml_text):
|
|
| 26 |
|
| 27 |
return '\n'.join(result)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
@app.route('/', methods=['GET', 'POST'])
|
| 30 |
def index():
|
| 31 |
processed_text = ""
|
|
@@ -37,6 +65,17 @@ def index():
|
|
| 37 |
|
| 38 |
return render_template('index.html', processed_text=processed_text, input_text=input_text)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
if __name__ == '__main__':
|
| 41 |
app.run(debug=True)
|
| 42 |
|
|
|
|
| 26 |
|
| 27 |
return '\n'.join(result)
|
| 28 |
|
| 29 |
+
|
| 30 |
+
def process_old_ssml_text(ssml_text):
|
| 31 |
+
"""
|
| 32 |
+
Process old SSML text format to extract and format content.
|
| 33 |
+
"""
|
| 34 |
+
result = []
|
| 35 |
+
|
| 36 |
+
# Process each line separately
|
| 37 |
+
lines = ssml_text.split('\n')
|
| 38 |
+
|
| 39 |
+
for line in lines:
|
| 40 |
+
# Remove DECIMAL and CURRENCY tags, keeping the spoken text and any trailing content
|
| 41 |
+
clean_line = re.sub(r'<(?:DECIMAL|CURRENCY|DATE|TIME|DURATION|TELEPHONE|EMAIL|URL|SYMBOL|ORDINAL|CARDINAL|MEASUREMENT|ROMAN|FRACTION|MATH_EXPRESSION|MATH_EQUATION|BANK_NUMBER|ADDRESS|ALPHA_NUMERIC|DIGIT|LONG_NUMBER|LATIN|PHONE|CONTACT|WEB|NUMERIC|ALPHABETIC|SPECIAL_CHAR|PUNCTUATION|SPACE|TAG_REPLACEMENT|LANGUAGE|LOCALE):\s*([^>]+)>\s*', r'\1 ', line)
|
| 42 |
+
|
| 43 |
+
# Remove textnorm tags
|
| 44 |
+
clean_line = re.sub(r'<textnorm[^>]*>([^<]*)</textnorm>', r'\1', clean_line)
|
| 45 |
+
|
| 46 |
+
# Replace specific symbols to match the expected output
|
| 47 |
+
clean_line = clean_line.replace('A☼M', 'A※M').replace('P☼M', 'P※M')
|
| 48 |
+
|
| 49 |
+
# Strip extra whitespace
|
| 50 |
+
clean_line = clean_line.strip()
|
| 51 |
+
|
| 52 |
+
result.append(clean_line)
|
| 53 |
+
|
| 54 |
+
return '\n'.join(result)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
@app.route('/', methods=['GET', 'POST'])
|
| 58 |
def index():
|
| 59 |
processed_text = ""
|
|
|
|
| 65 |
|
| 66 |
return render_template('index.html', processed_text=processed_text, input_text=input_text)
|
| 67 |
|
| 68 |
+
@app.route('/old', methods=['GET', 'POST'])
|
| 69 |
+
def old_index():
|
| 70 |
+
processed_text = ""
|
| 71 |
+
input_text = ""
|
| 72 |
+
|
| 73 |
+
if request.method == 'POST':
|
| 74 |
+
input_text = request.form.get('input_text', '')
|
| 75 |
+
processed_text = process_old_ssml_text(input_text)
|
| 76 |
+
|
| 77 |
+
return render_template('index.html', processed_text=processed_text, input_text=input_text)
|
| 78 |
+
|
| 79 |
if __name__ == '__main__':
|
| 80 |
app.run(debug=True)
|
| 81 |
|
templates/index.html
CHANGED
|
@@ -80,6 +80,28 @@
|
|
| 80 |
border-radius: 4px;
|
| 81 |
margin-bottom: 20px;
|
| 82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
</style>
|
| 84 |
</head>
|
| 85 |
<body>
|
|
@@ -91,8 +113,16 @@
|
|
| 91 |
<p>Example: <code>Hello <textnorm class='SomeClass' text='example'>world</textnorm></code> → <code>Hello world</code></p>
|
| 92 |
</div>
|
| 93 |
|
| 94 |
-
<form method="POST">
|
| 95 |
<div class="container">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
<div class="text-areas">
|
| 97 |
<div class="text-area-container">
|
| 98 |
<label for="input_text">Input (SSML text):</label>
|
|
@@ -114,6 +144,14 @@
|
|
| 114 |
</form>
|
| 115 |
|
| 116 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
function clearTextareas() {
|
| 118 |
document.getElementById('input_text').value = '';
|
| 119 |
document.getElementById('output_text').value = '';
|
|
|
|
| 80 |
border-radius: 4px;
|
| 81 |
margin-bottom: 20px;
|
| 82 |
}
|
| 83 |
+
.endpoint-selector {
|
| 84 |
+
display: flex;
|
| 85 |
+
align-items: center;
|
| 86 |
+
justify-content: center;
|
| 87 |
+
gap: 10px;
|
| 88 |
+
margin-bottom: 20px;
|
| 89 |
+
padding: 15px;
|
| 90 |
+
background-color: #f0f0f0;
|
| 91 |
+
border-radius: 4px;
|
| 92 |
+
}
|
| 93 |
+
.endpoint-selector label {
|
| 94 |
+
font-weight: bold;
|
| 95 |
+
margin-bottom: 0;
|
| 96 |
+
}
|
| 97 |
+
.endpoint-selector select {
|
| 98 |
+
padding: 8px 15px;
|
| 99 |
+
border: 1px solid #ccc;
|
| 100 |
+
border-radius: 4px;
|
| 101 |
+
font-size: 14px;
|
| 102 |
+
cursor: pointer;
|
| 103 |
+
background-color: white;
|
| 104 |
+
}
|
| 105 |
</style>
|
| 106 |
</head>
|
| 107 |
<body>
|
|
|
|
| 113 |
<p>Example: <code>Hello <textnorm class='SomeClass' text='example'>world</textnorm></code> → <code>Hello world</code></p>
|
| 114 |
</div>
|
| 115 |
|
| 116 |
+
<form method="POST" id="ssmlForm">
|
| 117 |
<div class="container">
|
| 118 |
+
<div class="endpoint-selector">
|
| 119 |
+
<label for="endpoint">Processing Mode:</label>
|
| 120 |
+
<select id="endpoint" name="endpoint">
|
| 121 |
+
<option value="/" selected>New Format (textnorm)</option>
|
| 122 |
+
<option value="/old">Old Format (DECIMAL/CURRENCY/DATE....)</option>
|
| 123 |
+
</select>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
<div class="text-areas">
|
| 127 |
<div class="text-area-container">
|
| 128 |
<label for="input_text">Input (SSML text):</label>
|
|
|
|
| 144 |
</form>
|
| 145 |
|
| 146 |
<script>
|
| 147 |
+
// Set form action based on selected endpoint
|
| 148 |
+
document.getElementById('endpoint').addEventListener('change', function() {
|
| 149 |
+
document.getElementById('ssmlForm').action = this.value;
|
| 150 |
+
});
|
| 151 |
+
|
| 152 |
+
// Set initial form action
|
| 153 |
+
document.getElementById('ssmlForm').action = document.getElementById('endpoint').value;
|
| 154 |
+
|
| 155 |
function clearTextareas() {
|
| 156 |
document.getElementById('input_text').value = '';
|
| 157 |
document.getElementById('output_text').value = '';
|
templates/ssml-old.html
ADDED
|
File without changes
|