Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
8 |
import re
|
9 |
import math
|
10 |
import logging
|
|
|
11 |
|
12 |
st.set_page_config(
|
13 |
page_title="AI Article Detection by DEJAN",
|
@@ -116,29 +117,36 @@ if st.button("Classify", type="primary"):
|
|
116 |
probs = F.softmax(logits, dim=-1).cpu()
|
117 |
preds = torch.argmax(probs, dim=-1).cpu()
|
118 |
|
119 |
-
#
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
avg = torch.mean(probs, dim=0)
|
144 |
model_ai = avg[0].item()
|
@@ -147,9 +155,4 @@ if st.button("Classify", type="primary"):
|
|
147 |
|
148 |
st.subheader(f"🤖 Model AI Likelihood: {model_ai*100:.1f}%")
|
149 |
st.subheader(f"🛠️ Heuristic AI Likelihood: {heuristic_ai*100:.1f}%")
|
150 |
-
st.subheader(f"⚖️ Combined AI Likelihood: {combined*100:.1f}%")
|
151 |
-
|
152 |
-
# Add progress bars for visual representation
|
153 |
-
st.progress(model_ai, text="Model AI Score")
|
154 |
-
st.progress(heuristic_ai, text="Heuristic Score")
|
155 |
-
st.progress(combined, text="Combined Score")
|
|
|
8 |
import re
|
9 |
import math
|
10 |
import logging
|
11 |
+
import pandas as pd
|
12 |
|
13 |
st.set_page_config(
|
14 |
page_title="AI Article Detection by DEJAN",
|
|
|
117 |
probs = F.softmax(logits, dim=-1).cpu()
|
118 |
preds = torch.argmax(probs, dim=-1).cpu()
|
119 |
|
120 |
+
# Create dataframe for sentences
|
121 |
+
sentences_data = []
|
122 |
+
for i, s in enumerate(sentences):
|
123 |
+
p = preds[i].item()
|
124 |
+
conf = probs[i, p].item()
|
125 |
+
label = "AI" if p == 0 else "Human"
|
126 |
|
127 |
+
sentences_data.append({
|
128 |
+
"sentence": s,
|
129 |
+
"classification": label,
|
130 |
+
"confidence": conf
|
131 |
+
})
|
132 |
+
|
133 |
+
# Display as dataframe with progress column
|
134 |
+
df = pd.DataFrame(sentences_data)
|
135 |
+
st.dataframe(
|
136 |
+
df,
|
137 |
+
column_config={
|
138 |
+
"sentence": st.column_config.TextColumn("Sentence"),
|
139 |
+
"classification": st.column_config.TextColumn("Classification"),
|
140 |
+
"confidence": st.column_config.ProgressColumn(
|
141 |
+
"Confidence",
|
142 |
+
help="Model's confidence in the classification",
|
143 |
+
format="%.2f",
|
144 |
+
min_value=0,
|
145 |
+
max_value=1,
|
146 |
+
),
|
147 |
+
},
|
148 |
+
hide_index=True,
|
149 |
+
)
|
150 |
|
151 |
avg = torch.mean(probs, dim=0)
|
152 |
model_ai = avg[0].item()
|
|
|
155 |
|
156 |
st.subheader(f"🤖 Model AI Likelihood: {model_ai*100:.1f}%")
|
157 |
st.subheader(f"🛠️ Heuristic AI Likelihood: {heuristic_ai*100:.1f}%")
|
158 |
+
st.subheader(f"⚖️ Combined AI Likelihood: {combined*100:.1f}%")
|
|
|
|
|
|
|
|
|
|