dejanseo commited on
Commit
964a94b
·
verified ·
1 Parent(s): f6a4aa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -28
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
- # Display sentences with Streamlit components instead of HTML
120
- for i, sentence in enumerate(sentences):
121
- is_ai = preds[i].item() == 0
122
- confidence = probs[i, preds[i].item()].item()
 
 
123
 
124
- # Use Streamlit components for display
125
- container = st.container(border=True)
126
- with container:
127
- if is_ai:
128
- st.markdown(f"🤖 **AI content** (confidence: {confidence:.2f})")
129
- else:
130
- st.markdown(f"👤 **Human content** (confidence: {confidence:.2f})")
131
- st.text(sentence)
132
-
133
- # Show word indicators
134
- words = tokenize(sentence)
135
- ai_indicators = [w for w in words if w in AI_WEIGHTS]
136
- human_indicators = [w for w in words if w in OG_WEIGHTS]
137
-
138
- if ai_indicators:
139
- st.text(f"AI indicators: {', '.join(ai_indicators)}")
140
- if human_indicators:
141
- st.text(f"Human indicators: {', '.join(human_indicators)}")
 
 
 
 
 
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}%")