Spaces:
Runtime error
Runtime error
Commit
ยท
7713a65
1
Parent(s):
6830e35
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,7 @@ def main():
|
|
18 |
import eli5
|
19 |
import shap
|
20 |
from custom_models import HF_DistilBertBasedModelAppDocs, HF_BertBasedModelAppDocs
|
|
|
21 |
|
22 |
# Initialize Spacy
|
23 |
nlp = spacy.load("en_core_web_sm")
|
@@ -92,8 +93,24 @@ def main():
|
|
92 |
else:
|
93 |
model = HF_DistilBertBasedModelAppDocs.from_pretrained("ferdmartin/HF_DistilBertBasedModelAppDocs").to(device)
|
94 |
return model
|
95 |
-
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# Streamlit app:
|
98 |
|
99 |
models_available = {"Logistic Regression":"models/baseline_model_lr2.joblib",
|
@@ -102,9 +119,9 @@ def main():
|
|
102 |
"BERT-based model": "ferdmartin/HF_BertBasedModelAppDocs"
|
103 |
}
|
104 |
|
105 |
-
st.set_page_config(page_title="AI/Human GradAppDocs", page_icon="
|
106 |
st.title("Academic Application Document Classifier")
|
107 |
-
st.header("Is it human-made ๐ or Generated with AI
|
108 |
|
109 |
# Check the model to use
|
110 |
def restore_prediction_state():
|
@@ -131,32 +148,19 @@ def main():
|
|
131 |
</style>
|
132 |
"""
|
133 |
st.markdown(hide_st_style, unsafe_allow_html=True)
|
134 |
-
|
135 |
# Use model
|
136 |
-
|
137 |
-
if
|
138 |
-
|
|
|
139 |
else:
|
140 |
-
|
141 |
-
|
142 |
-
if option in ("Naive Bayes", "Logistic Regression"):
|
143 |
-
prediction, predict_proba = nb_lr(model, text)
|
144 |
-
st.session_state["sklearn"] = True
|
145 |
-
else:
|
146 |
-
prediction, predict_proba = torch_pred(tokenizer, model, text)
|
147 |
-
st.session_state["torch"] = True
|
148 |
-
|
149 |
-
# Store the result in session state
|
150 |
-
st.session_state["color_pred"] = "blue" if prediction == 0 else "red"
|
151 |
-
prediction = pred_str(prediction)
|
152 |
-
st.session_state["prediction"] = prediction
|
153 |
-
st.session_state["predict_proba"] = predict_proba
|
154 |
-
st.session_state["text"] = text
|
155 |
-
|
156 |
# Print result
|
157 |
-
st.markdown(f"I think this text is: **:{st.session_state['color_pred']}[{st.session_state['prediction']}]** (Prediction probability: {st.session_state['predict_proba'] * 100}%)")
|
158 |
-
|
159 |
-
|
160 |
# Display the stored result if available
|
161 |
st.markdown(f"I think this text is: **:{st.session_state['color_pred']}[{st.session_state['prediction']}]** (Prediction probability: {st.session_state['predict_proba'] * 100}%)")
|
162 |
|
|
|
18 |
import eli5
|
19 |
import shap
|
20 |
from custom_models import HF_DistilBertBasedModelAppDocs, HF_BertBasedModelAppDocs
|
21 |
+
import docx
|
22 |
|
23 |
# Initialize Spacy
|
24 |
nlp = spacy.load("en_core_web_sm")
|
|
|
93 |
else:
|
94 |
model = HF_DistilBertBasedModelAppDocs.from_pretrained("ferdmartin/HF_DistilBertBasedModelAppDocs").to(device)
|
95 |
return model
|
|
|
96 |
|
97 |
+
def app_model(option, model, text):
|
98 |
+
with st.spinner("Wait for the magic ๐ช๐ฎ"):
|
99 |
+
# Use model
|
100 |
+
if option in ("Naive Bayes", "Logistic Regression"):
|
101 |
+
prediction, predict_proba = nb_lr(model, text)
|
102 |
+
st.session_state["sklearn"] = True
|
103 |
+
else:
|
104 |
+
prediction, predict_proba = torch_pred(tokenizer, model, text)
|
105 |
+
st.session_state["torch"] = True
|
106 |
+
|
107 |
+
# Store the result in session state
|
108 |
+
st.session_state["color_pred"] = "blue" if prediction == 0 else "red"
|
109 |
+
prediction = pred_str(prediction)
|
110 |
+
st.session_state["prediction"] = prediction
|
111 |
+
st.session_state["predict_proba"] = predict_proba
|
112 |
+
st.session_state["text"] = text
|
113 |
+
|
114 |
# Streamlit app:
|
115 |
|
116 |
models_available = {"Logistic Regression":"models/baseline_model_lr2.joblib",
|
|
|
119 |
"BERT-based model": "ferdmartin/HF_BertBasedModelAppDocs"
|
120 |
}
|
121 |
|
122 |
+
st.set_page_config(page_title="AI/Human GradAppDocs", page_icon="๐ค", layout="wide")
|
123 |
st.title("Academic Application Document Classifier")
|
124 |
+
st.header("Is it human-made ๐ or Generated with AI ๐ฆพ ? ")
|
125 |
|
126 |
# Check the model to use
|
127 |
def restore_prediction_state():
|
|
|
148 |
</style>
|
149 |
"""
|
150 |
st.markdown(hide_st_style, unsafe_allow_html=True)
|
151 |
+
col1, col2 = st.columns(2)
|
152 |
# Use model
|
153 |
+
with col1:
|
154 |
+
if st.button("Let's check this text!"):
|
155 |
+
if text.strip() == "":
|
156 |
+
st.error("Please enter some text")
|
157 |
else:
|
158 |
+
|
159 |
+
app_model(option, model, text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
# Print result
|
161 |
+
#st.markdown(f"I think this text is: **:{st.session_state['color_pred']}[{st.session_state['prediction']}]** (Prediction probability: {st.session_state['predict_proba'] * 100}%)")
|
162 |
+
|
163 |
+
if "prediction" in st.session_state:
|
164 |
# Display the stored result if available
|
165 |
st.markdown(f"I think this text is: **:{st.session_state['color_pred']}[{st.session_state['prediction']}]** (Prediction probability: {st.session_state['predict_proba'] * 100}%)")
|
166 |
|