|
6 | 6 | import plotly.express as px |
7 | 7 | import streamlit as st |
8 | 8 | from datasets import get_dataset_infos |
9 | | -from jinja2 import TemplateSyntaxError |
10 | 9 | from pygments import highlight |
11 | 10 | from pygments.formatters import HtmlFormatter |
12 | 11 | from pygments.lexers import DjangoLexer |
@@ -86,10 +85,13 @@ def show_jinja(t, width=WIDTH): |
86 | 85 | st.write(out, unsafe_allow_html=True) |
87 | 86 |
|
88 | 87 |
|
89 | | -def show_text(t, width=WIDTH): |
| 88 | +def show_text(t, width=WIDTH, with_markdown=False): |
90 | 89 | wrap = [textwrap.fill(subt, width=width, replace_whitespace=False) for subt in t.split("\n")] |
91 | 90 | wrap = "\n".join(wrap) |
92 | | - st.write(wrap, unsafe_allow_html=True) |
| 91 | + if with_markdown: |
| 92 | + st.write(wrap, unsafe_allow_html=True) |
| 93 | + else: |
| 94 | + st.text(wrap) |
93 | 95 |
|
94 | 96 |
|
95 | 97 | # |
@@ -373,10 +375,7 @@ def get_infos(d_name): |
373 | 375 | st.write(example) |
374 | 376 | if num_templates > 0: |
375 | 377 | with col2: |
376 | | - try: |
377 | | - prompt = template.apply(example, highlight_variables=True) |
378 | | - except (TemplateSyntaxError, TypeError): |
379 | | - prompt = template.apply(example, highlight_variables=False) |
| 378 | + prompt = template.apply(example, highlight_variables=False) |
380 | 379 | if prompt == [""]: |
381 | 380 | st.write("∅∅∅ *Blank result*") |
382 | 381 | else: |
@@ -453,7 +452,7 @@ def get_infos(d_name): |
453 | 452 | col1, _, _ = st.beta_columns([18, 1, 6]) |
454 | 453 | with col1: |
455 | 454 | if state.template_name is not None: |
456 | | - show_text(variety_guideline) |
| 455 | + show_text(variety_guideline, with_markdown=True) |
457 | 456 |
|
458 | 457 | # |
459 | 458 | # Edit the created or selected template |
|
0 commit comments