DeepActionPotential commited on
Commit
f463187
·
verified ·
1 Parent(s): 097428b

Update app.py

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