Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -159,77 +159,9 @@ def display_dialogue(hf_path: str):
|
|
| 159 |
with hf_fs.open(hf_path, "rb") as f:
|
| 160 |
txt = f.read().decode("utf-8")
|
| 161 |
txt = load_text(hf_path)
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
# f"<details><summary><b>Herr Laus</b></summary><div>{txt}</div></details><br>",
|
| 166 |
-
#unsafe_allow_html=True)
|
| 167 |
-
|
| 168 |
-
import html as py_html
|
| 169 |
-
from streamlit.components.v1 import html as st_html
|
| 170 |
-
|
| 171 |
-
def _md_inline_to_html(line: str) -> str:
|
| 172 |
-
"""
|
| 173 |
-
Minimal inline Markdown: **bold**, *italic*.
|
| 174 |
-
(Avoids bringing a full markdown parser; extend if needed.)
|
| 175 |
-
"""
|
| 176 |
-
esc = py_html.escape(line)
|
| 177 |
-
# bold: **text**
|
| 178 |
-
esc = re.sub(r"\*\*(.+?)\*\*", r"<strong>\1</strong>", esc)
|
| 179 |
-
# italic: *text* (ignore **bold** we already handled)
|
| 180 |
-
esc = re.sub(r"(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)", r"<em>\1</em>", esc)
|
| 181 |
-
return esc
|
| 182 |
-
|
| 183 |
-
def display_numbered_markdown_container(text: str,
|
| 184 |
-
title: str = "Dialogue",
|
| 185 |
-
width_chars: int = 80,
|
| 186 |
-
max_height_px: int = 520):
|
| 187 |
-
"""
|
| 188 |
-
Render a numbered, readable block with inline bold/italic preserved,
|
| 189 |
-
wrapped to `width_chars` and scrollable within a bordered container.
|
| 190 |
-
"""
|
| 191 |
-
block_id = f"dlg-{uuid.uuid4().hex[:8]}"
|
| 192 |
-
lines = text.replace("\r\n", "\n").replace("\r", "\n").split("\n")
|
| 193 |
-
|
| 194 |
-
# Convert each source line to HTML while preserving inline bold/italic
|
| 195 |
-
rows = []
|
| 196 |
-
for i, line in enumerate(lines, 1):
|
| 197 |
-
html_line = _md_inline_to_html(line) if line.strip() else " "
|
| 198 |
-
rows.append(f'''
|
| 199 |
-
<div class="row">
|
| 200 |
-
<span class="num">{i}</span>
|
| 201 |
-
<span class="txt">{html_line}</span>
|
| 202 |
-
</div>
|
| 203 |
-
''')
|
| 204 |
-
body = "\n".join(rows)
|
| 205 |
-
|
| 206 |
-
st.markdown(f"""
|
| 207 |
-
<style>
|
| 208 |
-
#{block_id} {{
|
| 209 |
-
border: 1px solid #e6e6e6; border-radius: .5rem; padding: .75rem;
|
| 210 |
-
max-height: {max_height_px}px; overflow-y: auto; background: #fff;
|
| 211 |
-
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
|
| 212 |
-
line-height: 1.5;
|
| 213 |
-
}}
|
| 214 |
-
#{block_id} .row {{
|
| 215 |
-
display: grid; grid-template-columns: 4ch 1fr; column-gap: 1ch; align-items: start;
|
| 216 |
-
margin: 0; padding: 0;
|
| 217 |
-
}}
|
| 218 |
-
#{block_id} .num {{
|
| 219 |
-
color: rgba(0,0,0,.55); text-align: right; user-select: none;
|
| 220 |
-
}}
|
| 221 |
-
/* Wrap the text column to a visual width of `width_chars` characters */
|
| 222 |
-
#{block_id} .txt {{
|
| 223 |
-
max-width: {width_chars}ch; white-space: pre-wrap; word-break: break-word;
|
| 224 |
-
}}
|
| 225 |
-
</style>
|
| 226 |
-
""", unsafe_allow_html=True)
|
| 227 |
-
|
| 228 |
-
with st.container(border=True):
|
| 229 |
-
#st.markdown(f"**{title}** \n*(wrapped to {width_chars} chars)*")
|
| 230 |
-
st.markdown(f'<div id="{block_id}">{body}</div>', unsafe_allow_html=True)
|
| 231 |
-
|
| 232 |
-
|
| 233 |
|
| 234 |
def display_image(image_path):
|
| 235 |
with hf_fs.open(image_path) as f:
|
|
@@ -285,8 +217,7 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 285 |
if f.name == 'image_name':
|
| 286 |
display_image(os.path.join(input_repo_path, 'images', value))
|
| 287 |
elif f.name == 'dialogue_name':
|
| 288 |
-
|
| 289 |
-
display_dialogue(value)
|
| 290 |
elif f.name == 'patient':
|
| 291 |
st.markdown(f"**Patient:** {value}")
|
| 292 |
else:
|
|
|
|
| 159 |
with hf_fs.open(hf_path, "rb") as f:
|
| 160 |
txt = f.read().decode("utf-8")
|
| 161 |
txt = load_text(hf_path)
|
| 162 |
+
st.markdown(
|
| 163 |
+
f"<details><summary><b>Session Transcription</b></summary><div>{txt}</div></details><br>",
|
| 164 |
+
unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
def display_image(image_path):
|
| 167 |
with hf_fs.open(image_path) as f:
|
|
|
|
| 217 |
if f.name == 'image_name':
|
| 218 |
display_image(os.path.join(input_repo_path, 'images', value))
|
| 219 |
elif f.name == 'dialogue_name':
|
| 220 |
+
display_dialogue(os.path.join(input_repo_path, 'dialogues', value))
|
|
|
|
| 221 |
elif f.name == 'patient':
|
| 222 |
st.markdown(f"**Patient:** {value}")
|
| 223 |
else:
|