kestrel256 commited on
Commit
1fcbd2d
·
verified ·
1 Parent(s): 4d73e98

Update Display of Card Information

Browse files

Instead of displaying card information in an st.text_area widget, display it in a st.markdown widget. This makes the card information read-only, to prevent accidentally changing it. It can still be selected and copied.

Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -400,9 +400,11 @@ def format_card_info(raw_json: str) -> str:
400
  # Remove quotes from value_str (clean but safe)
401
  value_str = value_str.replace('"', "")
402
 
 
403
  lines.append(f"{pretty_key}: {value_str}")
404
 
405
- return "\n".join(lines)
 
406
 
407
 
408
  # ============================================================================
@@ -444,20 +446,22 @@ with col_info:
444
  if st.session_state["card_info"]:
445
  raw = st.session_state["card_info"]
446
 
447
- # Remove optional prefix like "✓ Generated Card:"
448
- if raw.startswith(" Generated Card:"):
449
- # Split on the first '{'
450
- _, json_part = raw.split("{", 1)
451
- raw_json = "{" + json_part.strip()
452
  else:
453
- raw_json = raw
 
 
 
 
 
 
454
 
455
- pretty = format_card_info(raw_json)
456
- st.text_area(
457
- "Formatted Card Info",
458
- value=pretty,
459
- height=500
460
- )
461
  else:
462
  st.info("Card details will appear here after generation.")
463
 
 
400
  # Remove quotes from value_str (clean but safe)
401
  value_str = value_str.replace('"', "")
402
 
403
+ # Format each field on its own line with HTML line break for single spacing
404
  lines.append(f"{pretty_key}: {value_str}")
405
 
406
+ # Join with HTML line breaks to ensure single line spacing in markdown
407
+ return "<br>".join(lines)
408
 
409
 
410
  # ============================================================================
 
446
  if st.session_state["card_info"]:
447
  raw = st.session_state["card_info"]
448
 
449
+ # Check if text is already formatted (starts with card separator or horizontal rule)
450
+ if raw.startswith("########################") or raw.startswith("---"):
451
+ # Replace hash marks with horizontal rules if present
452
+ pretty = raw.replace("########################", "---")
 
453
  else:
454
+ # Remove optional prefix like "✓ Generated Card:"
455
+ if raw.startswith("✓ Generated Card:"):
456
+ # Split on the first '{'
457
+ _, json_part = raw.split("{", 1)
458
+ raw_json = "{" + json_part.strip()
459
+ else:
460
+ raw_json = raw
461
 
462
+ pretty = format_card_info(raw_json)
463
+
464
+ st.markdown(pretty, unsafe_allow_html=True)
 
 
 
465
  else:
466
  st.info("Card details will appear here after generation.")
467