CoolSpring commited on
Commit
7fa06e2
·
unverified ·
1 Parent(s): 0d8bade

Introduce MarkupSafe

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -3,6 +3,7 @@ import torch
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
  import nltk
5
  from nltk.tokenize import sent_tokenize
 
6
 
7
  # Set page config at the very beginning
8
  st.set_page_config(page_title="LLM Detector", layout="centered")
@@ -79,9 +80,8 @@ if st.button("Analyze and Highlight"):
79
  if text_input:
80
  with st.spinner("Analyzing text..."):
81
  overall_probability = classify_text(text_input)
82
- st.markdown(
83
  f"<h3>Overall probability of being AI-generated: <span style='color: {'red' if overall_probability > 0.5 else 'green'};'>{overall_probability:.2%}</span></h3>",
84
- unsafe_allow_html=True,
85
  )
86
 
87
  st.markdown("### Sentence-level analysis:")
@@ -89,9 +89,8 @@ if st.button("Analyze and Highlight"):
89
 
90
  for sentence, score in zip(sentences, scores):
91
  color = get_color(score)
92
- st.markdown(
93
- f"<div style='background-color: {color}; padding: 10px; margin: 5px 0; border-radius: 5px;'><strong>{score:.2%}</strong> - {sentence}</div>",
94
- unsafe_allow_html=True,
95
  )
96
  else:
97
  st.warning("Please enter some text to analyze.")
 
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
  import nltk
5
  from nltk.tokenize import sent_tokenize
6
+ from markupsafe import escape
7
 
8
  # Set page config at the very beginning
9
  st.set_page_config(page_title="LLM Detector", layout="centered")
 
80
  if text_input:
81
  with st.spinner("Analyzing text..."):
82
  overall_probability = classify_text(text_input)
83
+ st.html(
84
  f"<h3>Overall probability of being AI-generated: <span style='color: {'red' if overall_probability > 0.5 else 'green'};'>{overall_probability:.2%}</span></h3>",
 
85
  )
86
 
87
  st.markdown("### Sentence-level analysis:")
 
89
 
90
  for sentence, score in zip(sentences, scores):
91
  color = get_color(score)
92
+ st.html(
93
+ f"<div style='background-color: {color}; padding: 10px; margin: 5px 0; border-radius: 5px;'><strong>{score:.2%}</strong> - {escape(sentence)}</div>",
 
94
  )
95
  else:
96
  st.warning("Please enter some text to analyze.")