Spaces:
Running
Running
jaifar530
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -241,6 +241,57 @@ st.write(word_count)
|
|
241 |
press_me_button = st.button("Human or Robot?")
|
242 |
|
243 |
if press_me_button:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
predicted_author, author_probabilities = predict_author(new_text, loaded_model, tokenizer, label_encoder)
|
245 |
sorted_probabilities = sorted(author_probabilities.items(), key=lambda x: x[1], reverse=True)
|
246 |
|
|
|
241 |
press_me_button = st.button("Human or Robot?")
|
242 |
|
243 |
if press_me_button:
|
244 |
+
|
245 |
+
########## ML
|
246 |
+
|
247 |
+
word_count = len(re.findall(r'\w+', new_text))
|
248 |
+
st.write(word_count)
|
249 |
+
|
250 |
+
# Choose the appropriate model based on word count
|
251 |
+
if 10 <= word_count <= 34:
|
252 |
+
file_prefix = 'truncated_10_to_34'
|
253 |
+
elif 35 <= word_count <= 59:
|
254 |
+
file_prefix = 'truncated_35_to_59'
|
255 |
+
elif 60 <= word_count <= 84:
|
256 |
+
file_prefix = 'truncated_60_to_84'
|
257 |
+
elif 85 <= word_count <= 109:
|
258 |
+
file_prefix = 'truncated_85_to_109'
|
259 |
+
elif 110 <= word_count <= 134:
|
260 |
+
file_prefix = 'truncated_110_to_134'
|
261 |
+
elif 135 <= word_count <= 159:
|
262 |
+
file_prefix = 'truncated_135_to_159'
|
263 |
+
elif 160 <= word_count <= 184:
|
264 |
+
file_prefix = 'truncated_160_to_184'
|
265 |
+
elif 185 <= word_count <= 209:
|
266 |
+
file_prefix = 'truncated_185_to_209'
|
267 |
+
elif 210 <= word_count <= 234:
|
268 |
+
file_prefix = 'truncated_210_to_234'
|
269 |
+
elif 235 <= word_count <= 259:
|
270 |
+
file_prefix = 'truncated_235_to_259'
|
271 |
+
elif 260 <= word_count <= 284:
|
272 |
+
file_prefix = 'truncated_260_to_284'
|
273 |
+
else:
|
274 |
+
file_prefix = 'not_trancated_full_paragraph'
|
275 |
+
|
276 |
+
# Load the models and vectorizer
|
277 |
+
ridge_model = load_model(f"{file_prefix}_ridge_model.pkl")
|
278 |
+
extra_trees_model = load_model(f"{file_prefix}_extra_trees_model.pkl")
|
279 |
+
vectorizer = load_model(f"{file_prefix}_vectorizer.pkl")
|
280 |
+
|
281 |
+
# Transform the input
|
282 |
+
user_input_transformed = vectorizer.transform([new_text])
|
283 |
+
|
284 |
+
# Make predictions
|
285 |
+
ridge_prediction = ridge_model.predict(user_input_transformed)
|
286 |
+
extra_trees_prediction = extra_trees_model.predict(user_input_transformed)
|
287 |
+
|
288 |
+
if ridge_prediction == extra_trees_prediction:
|
289 |
+
st.write(f"The author is: {ridge_prediction[0]}")
|
290 |
+
else:
|
291 |
+
st.write(f"Different predictions. Ridge says: {ridge_prediction[0]}, Extra Trees says: {extra_trees_prediction[0]}")
|
292 |
+
|
293 |
+
|
294 |
+
########## DL
|
295 |
predicted_author, author_probabilities = predict_author(new_text, loaded_model, tokenizer, label_encoder)
|
296 |
sorted_probabilities = sorted(author_probabilities.items(), key=lambda x: x[1], reverse=True)
|
297 |
|