add markdown
Browse files
app.py
CHANGED
@@ -61,17 +61,26 @@ if __name__ == "__main__":
|
|
61 |
with demo:
|
62 |
gr.Markdown(
|
63 |
"""
|
64 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
"""
|
66 |
)
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
|
76 |
button.click(get_tokens_and_labels, inputs=prompt, outputs=highlighted_text)
|
77 |
|
|
|
61 |
with demo:
|
62 |
gr.Markdown(
|
63 |
"""
|
64 |
+
# Color Coded Text Generation
|
65 |
+
|
66 |
+
This is a demo of how you can obtain the probabilities of each token being generated, and use them to
|
67 |
+
color code the generated text π’π‘π΄. Feel free to clone this demo and modify it to your needs π€
|
68 |
+
|
69 |
+
Internally, it relies on [`compute_transition_scores`](https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.GenerationMixin.compute_transition_scores),
|
70 |
+
which was added in `transformers` v4.26.0.
|
71 |
"""
|
72 |
)
|
73 |
|
74 |
+
with gr.Row():
|
75 |
+
with gr.Column():
|
76 |
+
prompt = gr.Textbox(label="Prompt", lines=3, value="Today is")
|
77 |
+
button = gr.Button(f"Generate with {MODEL_NAME}")
|
78 |
+
with gr.Column():
|
79 |
+
highlighted_text = gr.HighlightedText(
|
80 |
+
label="Highlighted generation",
|
81 |
+
combine_adjacent=True,
|
82 |
+
show_legend=True,
|
83 |
+
).style(color_map=label_to_color)
|
84 |
|
85 |
button.click(get_tokens_and_labels, inputs=prompt, outputs=highlighted_text)
|
86 |
|