DeepActionPotential commited on
Commit
3d59151
·
verified ·
1 Parent(s): bf9beb4

Update app.py

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