Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,7 +65,7 @@ function_choices = ['Broadening Discussion',
|
|
| 65 |
default_choices = function_choices
|
| 66 |
|
| 67 |
fields: List[Field] = [
|
| 68 |
-
Field(name="patient", type="input_col", title="
|
| 69 |
Field(type="expander", title="**Session Transcription:** *(expand)*", children=[
|
| 70 |
Field(name="dialogue_name", type="input_col", title=""),
|
| 71 |
]),
|
|
@@ -167,7 +167,7 @@ import html as py_html
|
|
| 167 |
from streamlit.components.v1 import html as st_html
|
| 168 |
|
| 169 |
def display_dialogue_with_numbers(text: str, title="Dialogue"):
|
| 170 |
-
with st.
|
| 171 |
# optional: wrap long lines instead of horizontal scrolling
|
| 172 |
st.markdown(
|
| 173 |
"<style>.stCode pre {white-space: pre-wrap !important; word-break: break-word !important;}</style>",
|
|
@@ -175,26 +175,29 @@ def display_dialogue_with_numbers(text: str, title="Dialogue"):
|
|
| 175 |
)
|
| 176 |
st.code(text, language="markdown", line_numbers=True)
|
| 177 |
|
| 178 |
-
def
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
def display_image(image_path):
|
| 200 |
with hf_fs.open(image_path) as f:
|
|
@@ -250,8 +253,10 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 250 |
if f.name == 'image_name':
|
| 251 |
display_image(os.path.join(input_repo_path, 'images', value))
|
| 252 |
elif f.name == 'dialogue_name':
|
| 253 |
-
display_dialogue(os.path.join(input_repo_path, 'dialogues', value))
|
| 254 |
-
|
|
|
|
|
|
|
| 255 |
else:
|
| 256 |
st.write(value)
|
| 257 |
case 'markdown':
|
|
|
|
| 65 |
default_choices = function_choices
|
| 66 |
|
| 67 |
fields: List[Field] = [
|
| 68 |
+
Field(name="patient", type="input_col", title=" "),
|
| 69 |
Field(type="expander", title="**Session Transcription:** *(expand)*", children=[
|
| 70 |
Field(name="dialogue_name", type="input_col", title=""),
|
| 71 |
]),
|
|
|
|
| 167 |
from streamlit.components.v1 import html as st_html
|
| 168 |
|
| 169 |
def display_dialogue_with_numbers(text: str, title="Dialogue"):
|
| 170 |
+
with st.expander(f"{title} (line numbers)", expanded=True):
|
| 171 |
# optional: wrap long lines instead of horizontal scrolling
|
| 172 |
st.markdown(
|
| 173 |
"<style>.stCode pre {white-space: pre-wrap !important; word-break: break-word !important;}</style>",
|
|
|
|
| 175 |
)
|
| 176 |
st.code(text, language="markdown", line_numbers=True)
|
| 177 |
|
| 178 |
+
def _enable_code_wrap_once():
|
| 179 |
+
if not st.session_state.get("_code_wrap_css_added"):
|
| 180 |
+
st.markdown(
|
| 181 |
+
"<style>div[data-testid='stCode'] pre {white-space: pre-wrap !important; word-break: break-word !important;}</style>",
|
| 182 |
+
unsafe_allow_html=True,
|
| 183 |
+
)
|
| 184 |
+
st.session_state["_code_wrap_css_added"] = True
|
| 185 |
+
|
| 186 |
+
def display_dialogue_container(hf_path: str, title: str = "Dialogue", wrap: bool = True):
|
| 187 |
+
# read file from HF or local (uses your existing flags/objects)
|
| 188 |
+
if filesystem == 'hf':
|
| 189 |
+
with hf_fs.open(hf_path, "rb") as f:
|
| 190 |
+
txt = f.read().decode("utf-8")
|
| 191 |
+
else:
|
| 192 |
+
with open(hf_path, "r", encoding="utf-8") as f:
|
| 193 |
+
txt = f.read()
|
| 194 |
+
|
| 195 |
+
if wrap:
|
| 196 |
+
_enable_code_wrap_once()
|
| 197 |
+
|
| 198 |
+
with st.container(border=True):
|
| 199 |
+
st.markdown(f"**{title}**")
|
| 200 |
+
st.code(txt, language="markdown", line_numbers=True)
|
| 201 |
|
| 202 |
def display_image(image_path):
|
| 203 |
with hf_fs.open(image_path) as f:
|
|
|
|
| 253 |
if f.name == 'image_name':
|
| 254 |
display_image(os.path.join(input_repo_path, 'images', value))
|
| 255 |
elif f.name == 'dialogue_name':
|
| 256 |
+
#display_dialogue(os.path.join(input_repo_path, 'dialogues', value))
|
| 257 |
+
display_dialogue_container(os.path.join(input_repo_path, 'dialogues', value), title="Dialogue Transcription"))
|
| 258 |
+
elif f.name == 'patient':
|
| 259 |
+
st.markdown(f"**Patient:** {value}")
|
| 260 |
else:
|
| 261 |
st.write(value)
|
| 262 |
case 'markdown':
|