Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -56,33 +56,10 @@ def classify_text_likelihood(text: str) -> float:
|
|
56 |
net = ai_score - og_score
|
57 |
return 1 / (1 + math.exp(-SIGMOID_K * net))
|
58 |
|
59 |
-
def highlight_heuristic_words(text: str) -> str:
|
60 |
-
parts = re.split(r'(\b[a-z]{2,}\b)', text)
|
61 |
-
out = []
|
62 |
-
for part in parts:
|
63 |
-
lower = part.lower()
|
64 |
-
if lower in AI_WEIGHTS:
|
65 |
-
out.append(
|
66 |
-
f"<span style='text-decoration: underline; "
|
67 |
-
f"text-decoration-color: darkred; text-decoration-thickness: 2px;'>"
|
68 |
-
f"{part}</span>"
|
69 |
-
)
|
70 |
-
elif lower in OG_WEIGHTS:
|
71 |
-
out.append(
|
72 |
-
f"<span style='text-decoration: underline; "
|
73 |
-
f"text-decoration-color: darkgreen; text-decoration-thickness: 2px;'>"
|
74 |
-
f"{part}</span>"
|
75 |
-
)
|
76 |
-
else:
|
77 |
-
out.append(part)
|
78 |
-
return ''.join(out)
|
79 |
-
|
80 |
# --- Logging & Streamlit setup ---
|
81 |
logging.basicConfig(level=logging.INFO)
|
82 |
logger = logging.getLogger(__name__)
|
83 |
|
84 |
-
|
85 |
-
|
86 |
st.markdown("""
|
87 |
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
|
88 |
<style>
|
@@ -139,19 +116,29 @@ if st.button("Classify", type="primary"):
|
|
139 |
probs = F.softmax(logits, dim=-1).cpu()
|
140 |
preds = torch.argmax(probs, dim=-1).cpu()
|
141 |
|
142 |
-
|
143 |
-
for i,
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
avg = torch.mean(probs, dim=0)
|
157 |
model_ai = avg[0].item()
|
@@ -161,3 +148,8 @@ if st.button("Classify", type="primary"):
|
|
161 |
st.subheader(f"🤖 Model AI Likelihood: {model_ai*100:.1f}%")
|
162 |
st.subheader(f"🛠️ Heuristic AI Likelihood: {heuristic_ai*100:.1f}%")
|
163 |
st.subheader(f"⚖️ Combined AI Likelihood: {combined*100:.1f}%")
|
|
|
|
|
|
|
|
|
|
|
|
56 |
net = ai_score - og_score
|
57 |
return 1 / (1 + math.exp(-SIGMOID_K * net))
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# --- Logging & Streamlit setup ---
|
60 |
logging.basicConfig(level=logging.INFO)
|
61 |
logger = logging.getLogger(__name__)
|
62 |
|
|
|
|
|
63 |
st.markdown("""
|
64 |
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
|
65 |
<style>
|
|
|
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()
|
|
|
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")
|