gsarti commited on
Commit
edf08e6
1 Parent(s): 55479e9

Update HF Hub demo

Browse files
Files changed (1) hide show
  1. app.py +56 -9
app.py CHANGED
@@ -1,20 +1,67 @@
1
  import gradio as gr
 
2
  from gradio_highlightedtextbox import HighlightedTextbox
3
 
4
- def set_highlighted():
5
- return HighlightedTextbox(
6
- value=[("Non è qualcosa di cui vergognarsi: non è diverso dalle paure e", None), ("odie", "Potential issue"), ("personali", None), ("di altre cose", "Potential issue"), ("che", None), ("molta gente ha", "Potential issue"), (".", None)],
7
- interactive=True, label="Output", show_legend=True, show_label=False, legend_label="Test:", show_legend_label=True
 
 
8
  )
9
 
 
10
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  with gr.Row():
12
- gr.Textbox(" It is not something to be ashamed of: it is no different from the personal fears and dislikes of other things that very many people have.", interactive=False)
 
 
 
 
 
 
13
  high = HighlightedTextbox(
14
- interactive=True, label="Input", show_legend=True, show_label=False, legend_label="Legend:", show_legend_label=True
 
 
 
 
 
 
15
  )
16
  button = gr.Button("Submit")
17
- button.click(fn=set_highlighted, inputs=[], outputs=high)
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()