emvecchi commited on
Commit
a899671
·
verified ·
1 Parent(s): 07fc95c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -26
app.py CHANGED
@@ -66,7 +66,7 @@ default_choices = function_choices
66
 
67
  fields: List[Field] = [
68
  Field(name="patient", type="input_col", title="**Patient::**"),
69
- Field(type="expander", title="**Preceeding Comment:** *(expand)*", children=[
70
  Field(name="dialogue_name", type="input_col", title=""),
71
  ]),
72
 
@@ -155,37 +155,34 @@ def get_path():
155
 
156
  def display_dialogue(hf_path: str):
157
  txt = load_text(hf_path)
158
- markdown_with_line_numbers(txt, title="Session Transcription")
159
  #st.markdown(
160
  # f"<details><summary><b>Herr Laus</b></summary><div>{txt}</div></details><br>",
161
  #unsafe_allow_html=True)
162
 
163
- def markdown_with_line_numbers(text: str, title: str | None = None):
164
- # escape to avoid HTML injection, keep original newlines
165
- escaped = html.escape(text)
166
- lines = escaped.splitlines()
167
- # keep blank lines visible so numbering doesn't collapse
168
- body = "".join(f"<span>{ln or '&nbsp;'}</span>" for ln in lines)
169
 
170
- css = """
 
 
 
 
 
 
171
  <style>
172
- .ln pre { counter-reset: line; margin: 0; white-space: pre-wrap; }
173
- .ln pre span { display: block; }
174
- .ln pre span::before {
175
- counter-increment: line;
176
- content: counter(line);
177
- display: inline-block;
178
- width: 4ch; /* gutter width */
179
- margin-right: 1ch;
180
- text-align: right;
181
- opacity: .6;
182
- }
183
- .ln { border: 1px solid #ddd; border-radius: .5rem; padding: .75rem; }
184
  </style>
185
- """
186
- st.markdown(css + (f"<p><b>{html.escape(title)}</b></p>" if title else "") +
187
- f'<div class="ln"><pre>{body}</pre></div>',
188
- unsafe_allow_html=True)
189
 
190
  def display_image(image_path):
191
  with hf_fs.open(image_path) as f:
@@ -391,7 +388,7 @@ st.markdown(
391
  div[data-testid="stMarkdownContainer"] > p {
392
  font-size: 1rem;
393
  }
394
- section.main > div {max-width:100rem}
395
  </style>
396
  """, unsafe_allow_html=True)
397
 
 
66
 
67
  fields: List[Field] = [
68
  Field(name="patient", type="input_col", title="**Patient::**"),
69
+ Field(type="expander", title="**Session Transcription:** *(expand)*", children=[
70
  Field(name="dialogue_name", type="input_col", title=""),
71
  ]),
72
 
 
155
 
156
  def display_dialogue(hf_path: str):
157
  txt = load_text(hf_path)
158
+ markdown_with_line_numbers(txt)
159
  #st.markdown(
160
  # f"<details><summary><b>Herr Laus</b></summary><div>{txt}</div></details><br>",
161
  #unsafe_allow_html=True)
162
 
163
+ import html as py_html
164
+ from streamlit.components.v1 import html as st_html
 
 
 
 
165
 
166
+ def markdown_with_line_numbers(text: str, height: int = 500):
167
+ # Number *source lines* (not wrapped visual lines)
168
+ escaped = py_html.escape(text)
169
+ body = "".join(f"<span>{ln or '&nbsp;'}</span>" for ln in escaped.splitlines())
170
+
171
+ st_html(f"""
172
+ <div class="ln"><pre>{body}</pre></div>
173
  <style>
174
+ .ln {{ counter-reset: line; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
175
+ font-size: 0.95rem; border: 1px solid #ddd; border-radius: .5rem;
176
+ padding: .75rem; background: #fff; max-height: 100%; overflow: auto; }}
177
+ .ln pre {{ white-space: pre-wrap; margin: 0; }}
178
+ .ln pre span {{ display: block; }}
179
+ .ln pre span::before {{
180
+ counter-increment: line;
181
+ content: counter(line);
182
+ display: inline-block; width: 4ch; margin-right: 1ch; text-align: right; opacity: .6;
183
+ }}
 
 
184
  </style>
185
+ """, height=height, scrolling=True)
 
 
 
186
 
187
  def display_image(image_path):
188
  with hf_fs.open(image_path) as f:
 
388
  div[data-testid="stMarkdownContainer"] > p {
389
  font-size: 1rem;
390
  }
391
+ section.main > div {max-width:80rem}
392
  </style>
393
  """, unsafe_allow_html=True)
394