davda54
commited on
Commit
·
ba91ea6
1
Parent(s):
0d44734
prettytable test
Browse files- app.py +23 -43
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
description = """
|
|
@@ -78,52 +79,31 @@ edge_labels = [
|
|
| 78 |
if line and not line.startswith("#")
|
| 79 |
]
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
|
| 84 |
gr.HTML(description)
|
| 85 |
-
|
| 86 |
-
gr.Dataframe([forms], interactive=False, type="array")
|
| 87 |
-
|
| 88 |
-
with gr.Accordion("Lemmas", open=True):
|
| 89 |
-
gr.Dataframe([lemmas], interactive=False, type="array")
|
| 90 |
-
|
| 91 |
-
with gr.Accordion("UPOS", open=True):
|
| 92 |
-
gr.Dataframe([upos], interactive=False, type="array")
|
| 93 |
-
|
| 94 |
-
with gr.Accordion("XPOS", open=True):
|
| 95 |
-
gr.Dataframe([xpos], interactive=False, type="array")
|
| 96 |
-
|
| 97 |
-
gr.HTML("""<table>
|
| 98 |
-
<thead>
|
| 99 |
-
<tr>
|
| 100 |
-
<th>City name</th>
|
| 101 |
-
<th>Area</th>
|
| 102 |
-
<th>Population</th>
|
| 103 |
-
<th>Annual Rainfall</th>
|
| 104 |
-
</tr>
|
| 105 |
-
</thead>
|
| 106 |
-
<tbody>
|
| 107 |
-
<tr>
|
| 108 |
-
<td>Adelaide</td>
|
| 109 |
-
<td>1295</td>
|
| 110 |
-
<td>1158259</td>
|
| 111 |
-
<td>600.5</td>
|
| 112 |
-
</tr>
|
| 113 |
-
<tr>
|
| 114 |
-
<td>Brisbane</td>
|
| 115 |
-
<td>5905</td>
|
| 116 |
-
<td>1857594</td>
|
| 117 |
-
<td>1146.4</td>
|
| 118 |
-
</tr>
|
| 119 |
-
</tbody>
|
| 120 |
-
</table>""")
|
| 121 |
-
|
| 122 |
-
with gr.Accordion("UFeats", open=True):
|
| 123 |
-
feats = [feat.split("|") for feat in feats]
|
| 124 |
-
max_len = max([len(feat) for feat in feats])
|
| 125 |
-
feats = [feat + [""] * (max_len - len(feat)) for feat in feats]
|
| 126 |
-
feats = list(zip(*feats))
|
| 127 |
-
gr.Dataframe(feats, interactive=False, type="array")
|
| 128 |
|
| 129 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import prettytable
|
| 3 |
|
| 4 |
|
| 5 |
description = """
|
|
|
|
| 79 |
if line and not line.startswith("#")
|
| 80 |
]
|
| 81 |
|
| 82 |
+
def render_table(forms, lemmas, upos, xpos, feats, metadata, edges, edge_labels):
|
| 83 |
+
feats = [feat.split("|") for feat in feats]
|
| 84 |
+
max_len = max([len(feat) for feat in feats])
|
| 85 |
+
feats = [feat + [""] * (max_len - len(feat)) for feat in feats]
|
| 86 |
+
feats = list(zip(*feats))
|
| 87 |
+
|
| 88 |
+
array = [
|
| 89 |
+
["<b>forms</b> "] + forms,
|
| 90 |
+
["<b>lemmas</b> "] + lemmas,
|
| 91 |
+
["<b>upos</b> "] + upos,
|
| 92 |
+
["<b>xpos</b> "] + xpos,
|
| 93 |
+
["<b>feats</b> "] + feats[0],
|
| 94 |
+
*([""] + row for row in feats[1:])
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
table = prettytable.PrettyTable()
|
| 98 |
+
table.field_names = array[0]
|
| 99 |
+
for row in array[1:]:
|
| 100 |
+
table.add_row(row)
|
| 101 |
+
|
| 102 |
+
return table.get_html_string()
|
| 103 |
|
| 104 |
|
| 105 |
with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
|
| 106 |
gr.HTML(description)
|
| 107 |
+
gr.HTML(render_table(forms, lemmas, upos, xpos, feats, metadata, edges, edge_labels))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
prettytable
|