Spaces:
Sleeping
Sleeping
bsg25 Claude commited on
Commit ·
e8e90f9
1
Parent(s): 8cd7f6d
Add aligned view tab for rhythm and meter analysis
Browse filesAdded a new "Aligned View" tab that displays rhythm, original text, and meter in a three-row table format with character-to-syllable alignment. The view uses monospace formatting to align rhythm and meter characters with the words in the original text.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -38,6 +38,76 @@ def run_all_transformations(text):
|
|
| 38 |
return combined
|
| 39 |
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# Create Gradio interface with tabs
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
gr.Markdown("# MetricalT5 Model")
|
|
@@ -67,4 +137,10 @@ with gr.Blocks() as demo:
|
|
| 67 |
all_button = gr.Button("Run All Transformations")
|
| 68 |
all_button.click(run_all_transformations, inputs=all_input, outputs=all_output)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
demo.launch()
|
|
|
|
| 38 |
return combined
|
| 39 |
|
| 40 |
|
| 41 |
+
def create_aligned_table(text):
|
| 42 |
+
"""Create an aligned table with rhythm, original text, and meter"""
|
| 43 |
+
meter = transform_to_meter(text)
|
| 44 |
+
rhythm = transform_to_rhythm(text)
|
| 45 |
+
|
| 46 |
+
# Split text into syllables (simple word-based splitting for now)
|
| 47 |
+
words = text.split()
|
| 48 |
+
rhythm_chars = list(rhythm.replace(" ", ""))
|
| 49 |
+
meter_chars = list(meter.replace(" ", ""))
|
| 50 |
+
|
| 51 |
+
# Build aligned rows
|
| 52 |
+
rhythm_row = []
|
| 53 |
+
text_row = []
|
| 54 |
+
meter_row = []
|
| 55 |
+
|
| 56 |
+
rhythm_idx = 0
|
| 57 |
+
meter_idx = 0
|
| 58 |
+
|
| 59 |
+
for word in words:
|
| 60 |
+
# For each word, try to align rhythm and meter characters
|
| 61 |
+
word_len = len(word)
|
| 62 |
+
|
| 63 |
+
# Get rhythm chars for this word
|
| 64 |
+
rhythm_segment = ""
|
| 65 |
+
for _ in range(word_len):
|
| 66 |
+
if rhythm_idx < len(rhythm_chars):
|
| 67 |
+
rhythm_segment += rhythm_chars[rhythm_idx]
|
| 68 |
+
rhythm_idx += 1
|
| 69 |
+
|
| 70 |
+
# Get meter chars for this word
|
| 71 |
+
meter_segment = ""
|
| 72 |
+
for _ in range(word_len):
|
| 73 |
+
if meter_idx < len(meter_chars):
|
| 74 |
+
meter_segment += meter_chars[meter_idx]
|
| 75 |
+
meter_idx += 1
|
| 76 |
+
|
| 77 |
+
# Pad to match word length
|
| 78 |
+
rhythm_segment = rhythm_segment.ljust(word_len)
|
| 79 |
+
meter_segment = meter_segment.ljust(word_len)
|
| 80 |
+
|
| 81 |
+
rhythm_row.append(rhythm_segment)
|
| 82 |
+
text_row.append(word)
|
| 83 |
+
meter_row.append(meter_segment)
|
| 84 |
+
|
| 85 |
+
# Join with spaces
|
| 86 |
+
rhythm_line = " ".join(rhythm_row)
|
| 87 |
+
text_line = " ".join(text_row)
|
| 88 |
+
meter_line = " ".join(meter_row)
|
| 89 |
+
|
| 90 |
+
# Create HTML table
|
| 91 |
+
html_table = f"""
|
| 92 |
+
<table style="font-family: monospace; border-collapse: collapse; width: 100%;">
|
| 93 |
+
<tr style="border-bottom: 1px solid #ddd;">
|
| 94 |
+
<td style="padding: 8px;"><strong>Rhythm:</strong></td>
|
| 95 |
+
<td style="padding: 8px;">{rhythm_line}</td>
|
| 96 |
+
</tr>
|
| 97 |
+
<tr style="border-bottom: 1px solid #ddd;">
|
| 98 |
+
<td style="padding: 8px;"><strong>Original:</strong></td>
|
| 99 |
+
<td style="padding: 8px;">{text_line}</td>
|
| 100 |
+
</tr>
|
| 101 |
+
<tr>
|
| 102 |
+
<td style="padding: 8px;"><strong>Meter:</strong></td>
|
| 103 |
+
<td style="padding: 8px;">{meter_line}</td>
|
| 104 |
+
</tr>
|
| 105 |
+
</table>
|
| 106 |
+
"""
|
| 107 |
+
|
| 108 |
+
return html_table
|
| 109 |
+
|
| 110 |
+
|
| 111 |
# Create Gradio interface with tabs
|
| 112 |
with gr.Blocks() as demo:
|
| 113 |
gr.Markdown("# MetricalT5 Model")
|
|
|
|
| 137 |
all_button = gr.Button("Run All Transformations")
|
| 138 |
all_button.click(run_all_transformations, inputs=all_input, outputs=all_output)
|
| 139 |
|
| 140 |
+
with gr.Tab("Aligned View"):
|
| 141 |
+
aligned_input = gr.Textbox(lines=5, placeholder="Enter text here...")
|
| 142 |
+
aligned_output = gr.HTML(label="Aligned Table")
|
| 143 |
+
aligned_button = gr.Button("Generate Aligned View")
|
| 144 |
+
aligned_button.click(create_aligned_table, inputs=aligned_input, outputs=aligned_output)
|
| 145 |
+
|
| 146 |
demo.launch()
|