Spaces:
Runtime error
Runtime error
Update HF Hub demo
Browse files
app.py
CHANGED
@@ -1,20 +1,67 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from gradio_highlightedtextbox import HighlightedTextbox
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
)
|
9 |
|
|
|
10 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
with gr.Row():
|
12 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
high = HighlightedTextbox(
|
14 |
-
interactive=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
)
|
16 |
button = gr.Button("Submit")
|
17 |
-
button.click(
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
from gradio_highlightedtextbox import HighlightedTextbox
|
4 |
|
5 |
+
|
6 |
+
def convert_tagged_text_to_highlighted_text(
|
7 |
+
tagged_text: str, tag_id: str, tag_open: str, tag_close: str
|
8 |
+
) -> list[tuple[str, str | None]]:
|
9 |
+
return HighlightedTextbox.tagged_text_to_tuples(
|
10 |
+
tagged_text, tag_id, tag_open, tag_close
|
11 |
)
|
12 |
|
13 |
+
|
14 |
with gr.Blocks() as demo:
|
15 |
+
tag_id = gr.Textbox(
|
16 |
+
"Potential issue",
|
17 |
+
label="Tag ID",
|
18 |
+
show_label=True,
|
19 |
+
info="Insert a tag ID to use in the highlighted textbox.",
|
20 |
+
)
|
21 |
+
tag_open = gr.Textbox(
|
22 |
+
"<h>",
|
23 |
+
label="Tag open",
|
24 |
+
show_label=True,
|
25 |
+
info="Insert a tag to mark the beginning of a highlighted section.",
|
26 |
+
)
|
27 |
+
tag_close = gr.Textbox(
|
28 |
+
"</h>",
|
29 |
+
label="Tag close",
|
30 |
+
show_label=True,
|
31 |
+
info="Insert a tag to mark the end of a highlighted section.",
|
32 |
+
)
|
33 |
with gr.Row():
|
34 |
+
tagged = gr.Textbox(
|
35 |
+
"It is not something to be ashamed of: it is no different from the <h>personal fears</h> and <h>dislikes</h> of other things that <h>very many people</h> have.",
|
36 |
+
interactive=True,
|
37 |
+
label="Input",
|
38 |
+
show_label=True,
|
39 |
+
info="Insert a text with <h>...</h> tags to mark spans that will be highlighted.",
|
40 |
+
)
|
41 |
high = HighlightedTextbox(
|
42 |
+
interactive=True,
|
43 |
+
label="Output",
|
44 |
+
info="Highlighted textbox.",
|
45 |
+
show_legend=True,
|
46 |
+
show_label=True,
|
47 |
+
legend_label="Legend:",
|
48 |
+
show_legend_label=True,
|
49 |
)
|
50 |
button = gr.Button("Submit")
|
51 |
+
button.click(
|
52 |
+
fn=convert_tagged_text_to_highlighted_text,
|
53 |
+
inputs=[tagged, tag_id, tag_open, tag_close],
|
54 |
+
outputs=high,
|
55 |
+
)
|
56 |
+
# Initialization does not work
|
57 |
+
high = HighlightedTextbox(
|
58 |
+
convert_tagged_text_to_highlighted_text(
|
59 |
+
tagged.value, tag_id.value, tag_open.value, tag_close.value
|
60 |
+
),
|
61 |
+
interactive=True,
|
62 |
+
label="Does not work",
|
63 |
+
show_label=True,
|
64 |
+
)
|
65 |
+
|
66 |
|
67 |
+
demo.launch()
|