Spaces:
Sleeping
Sleeping
File size: 1,736 Bytes
3d59151 cec02aa 3d59151 e46d899 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import nltk
try:
nltk.data.find('corpora/stopwords')
except LookupError:
nltk.download('stopwords', quiet=True)
import streamlit as st
from utils import load_model, preprocess_text
model = load_model('./models/best_model.joblib')
min_words_number = 100
def check_generated_text(text):
filtered_text = preprocess_text(text)
prediction = model.predict([filtered_text])
return not int(prediction[0])
# Load styles
with open("styles.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
# Title
st.title("Generated Text Checker")
# Initialize session state
if "check_clicked" not in st.session_state:
st.session_state.check_clicked = False
# Use a form to isolate the check action
with st.form("text_check_form"):
user_input = st.text_area(
f"Enter text to check",
height=400,
placeholder=f"Paste your generated text here... it should be at least {min_words_number} words"
)
submitted = st.form_submit_button("Check text")
# Handle form submission
if submitted:
st.session_state.check_clicked = True
# Only run check when button is clicked
if st.session_state.check_clicked:
with st.spinner("Checking text..."):
current_length = len(user_input.split())
if current_length >= min_words_number:
result = check_generated_text(user_input)
if result:
st.info("✅ The text appears to be human-written!")
else:
st.info("🤖 The text appears to be AI-generated.")
else:
st.warning(f"Please enter at least {min_words_number} words.")
# Reset check state
st.session_state.check_clicked = False |