sundaram07 commited on
Commit
f89536d
Β·
verified Β·
1 Parent(s): b68ab79

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +19 -10
src/streamlit_app.py CHANGED
@@ -27,7 +27,7 @@ def predict_sentence_ai_probability(sentence):
27
  inputs = tokenizer(sentence, return_tensors="tf", truncation=True, padding=True)
28
  outputs = model(inputs)
29
  logits = outputs.logits
30
- prob_ai = tf.sigmoid(logits)[0][0].numpy() # for binary classification
31
  return prob_ai
32
 
33
  # πŸ“Š Analyze all sentences
@@ -53,6 +53,12 @@ st.set_page_config(page_title="AI Detector", layout="wide")
53
  st.title("🧠 AI Content Detector")
54
  st.markdown("This app detects the percentage of **AI-generated content** based on sentence-level analysis using DistilBERT.")
55
 
 
 
 
 
 
 
56
  # πŸ“‹ User Input Area
57
  user_input = st.text_area("πŸ“‹ Paste your text below to check for AI-generated sentences:", height=300)
58
 
@@ -61,15 +67,18 @@ if st.button("πŸ” Analyze"):
61
  if not user_input.strip():
62
  st.warning("⚠️ Please enter some text to analyze.")
63
  else:
64
- # Run analysis
 
65
  ai_percentage, analysis_results = predict_ai_generated_percentage(user_input)
 
 
66
 
67
- # πŸ” Sentence-Level Results
68
- st.subheader("πŸ” Sentence-level Analysis")
69
- for i, (sentence, prob, is_ai) in enumerate(analysis_results, start=1):
70
- label = "🟒 Human" if not is_ai else "πŸ”΄ AI"
71
- st.markdown(f"**{i}.** _{sentence}_\n\n β†’ {label}")
 
72
 
73
- # πŸ“Š Final Result
74
- st.subheader("πŸ“Š Final Result")
75
- st.success(f"Estimated **AI-generated content**: **{ai_percentage:.2f}%**")
 
27
  inputs = tokenizer(sentence, return_tensors="tf", truncation=True, padding=True)
28
  outputs = model(inputs)
29
  logits = outputs.logits
30
+ prob_ai = tf.sigmoid(logits)[0][0].numpy()
31
  return prob_ai
32
 
33
  # πŸ“Š Analyze all sentences
 
53
  st.title("🧠 AI Content Detector")
54
  st.markdown("This app detects the percentage of **AI-generated content** based on sentence-level analysis using DistilBERT.")
55
 
56
+ # Initialize session state to avoid duplicates
57
+ if "last_input" not in st.session_state:
58
+ st.session_state.last_input = ""
59
+ st.session_state.results = None
60
+ st.session_state.percentage = None
61
+
62
  # πŸ“‹ User Input Area
63
  user_input = st.text_area("πŸ“‹ Paste your text below to check for AI-generated sentences:", height=300)
64
 
 
67
  if not user_input.strip():
68
  st.warning("⚠️ Please enter some text to analyze.")
69
  else:
70
+ # Store in session_state to avoid duplicates
71
+ st.session_state.last_input = user_input
72
  ai_percentage, analysis_results = predict_ai_generated_percentage(user_input)
73
+ st.session_state.results = analysis_results
74
+ st.session_state.percentage = ai_percentage
75
 
76
+ # Display only if results are present
77
+ if st.session_state.results is not None:
78
+ st.subheader("πŸ” Sentence-level Analysis")
79
+ for i, (sentence, prob, is_ai) in enumerate(st.session_state.results, start=1):
80
+ label = "🟒 Human" if not is_ai else "πŸ”΄ AI"
81
+ st.markdown(f"**{i}.** _{sentence}_\n\n β†’ {label}")
82
 
83
+ st.subheader("πŸ“Š Final Result")
84
+ st.success(f"Estimated **AI-generated content**: **{st.session_state.percentage:.2f}%**")