Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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()
|
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 |
-
#
|
|
|
65 |
ai_percentage, analysis_results = predict_ai_generated_percentage(user_input)
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
72 |
|
73 |
-
|
74 |
-
|
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}%**")
|
|