Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from typing import List, Dict
|
|
| 6 |
import gradio as gr
|
| 7 |
import plotly.graph_objects as go
|
| 8 |
|
|
|
|
| 9 |
# --------- Heuristic Scoring Logic ---------
|
| 10 |
|
| 11 |
SENTENCE_SPLIT_PATTERN = re.compile(r'(?<=[.!?])\s+')
|
|
@@ -45,10 +46,22 @@ def label_from_score(score: int) -> str:
|
|
| 45 |
return "Low–Medium Trust"
|
| 46 |
return "Low Trust"
|
| 47 |
|
|
|
|
| 48 |
def make_gauge(score: int):
|
| 49 |
-
# keep score in range
|
| 50 |
score = max(0, min(100, score))
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
fig = go.Figure(
|
| 53 |
go.Indicator(
|
| 54 |
mode="gauge+number",
|
|
@@ -59,38 +72,48 @@ def make_gauge(score: int):
|
|
| 59 |
},
|
| 60 |
gauge={
|
| 61 |
"shape": "angular",
|
| 62 |
-
"axis": {
|
| 63 |
-
"range": [0, 100],
|
| 64 |
-
"visible": False, # hide tick labels
|
| 65 |
-
},
|
| 66 |
-
# transparent bar so we only see the needle + background arc
|
| 67 |
"bar": {
|
| 68 |
-
"color": "rgba(0,0,0,0)",
|
| 69 |
-
"thickness": 0.
|
| 70 |
},
|
| 71 |
"bgcolor": "white",
|
| 72 |
"borderwidth": 0,
|
| 73 |
-
# three shades of blue across the whole arc
|
| 74 |
"steps": [
|
| 75 |
-
{"range": [0, 33], "color": "#c7d2fe"},
|
| 76 |
-
{"range": [33, 66], "color": "#60a5fa"},
|
| 77 |
-
{"range": [66, 100], "color": "#1d4ed8"},
|
| 78 |
],
|
| 79 |
},
|
| 80 |
domain={"x": [0, 1], "y": [0, 1]},
|
| 81 |
)
|
| 82 |
)
|
| 83 |
|
| 84 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
fig.update_layout(
|
| 86 |
margin=dict(t=30, b=10, l=20, r=20),
|
| 87 |
-
height=220
|
| 88 |
)
|
| 89 |
|
| 90 |
return fig
|
| 91 |
|
| 92 |
|
| 93 |
-
|
| 94 |
def analyze_text(text: str, is_ai_generated: bool):
|
| 95 |
text = text.strip()
|
| 96 |
if not text:
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
import plotly.graph_objects as go
|
| 8 |
|
| 9 |
+
|
| 10 |
# --------- Heuristic Scoring Logic ---------
|
| 11 |
|
| 12 |
SENTENCE_SPLIT_PATTERN = re.compile(r'(?<=[.!?])\s+')
|
|
|
|
| 46 |
return "Low–Medium Trust"
|
| 47 |
return "Low Trust"
|
| 48 |
|
| 49 |
+
import numpy as np
|
| 50 |
def make_gauge(score: int):
|
|
|
|
| 51 |
score = max(0, min(100, score))
|
| 52 |
|
| 53 |
+
# Convert score (0–100) into radians for needle angle
|
| 54 |
+
# Gauge runs from -90° (left) to +90° (right)
|
| 55 |
+
angle = (score / 100) * 180 - 90
|
| 56 |
+
angle_rad = angle * 3.14159 / 180
|
| 57 |
+
|
| 58 |
+
# Needle length
|
| 59 |
+
r = 0.75
|
| 60 |
+
|
| 61 |
+
# Needle endpoint
|
| 62 |
+
x = 0.5 + r * np.cos(angle_rad)
|
| 63 |
+
y = 0.0 + r * np.sin(angle_rad)
|
| 64 |
+
|
| 65 |
fig = go.Figure(
|
| 66 |
go.Indicator(
|
| 67 |
mode="gauge+number",
|
|
|
|
| 72 |
},
|
| 73 |
gauge={
|
| 74 |
"shape": "angular",
|
| 75 |
+
"axis": {"range": [0, 100], "visible": False},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
"bar": {
|
| 77 |
+
"color": "rgba(0,0,0,0)", # keep transparent
|
| 78 |
+
"thickness": 0.1
|
| 79 |
},
|
| 80 |
"bgcolor": "white",
|
| 81 |
"borderwidth": 0,
|
|
|
|
| 82 |
"steps": [
|
| 83 |
+
{"range": [0, 33], "color": "#c7d2fe"},
|
| 84 |
+
{"range": [33, 66], "color": "#60a5fa"},
|
| 85 |
+
{"range": [66, 100], "color": "#1d4ed8"},
|
| 86 |
],
|
| 87 |
},
|
| 88 |
domain={"x": [0, 1], "y": [0, 1]},
|
| 89 |
)
|
| 90 |
)
|
| 91 |
|
| 92 |
+
# Add needle (triangle or line)
|
| 93 |
+
fig.add_shape(
|
| 94 |
+
type="line",
|
| 95 |
+
x0=0.5, y0=0.0,
|
| 96 |
+
x1=x, y1=y,
|
| 97 |
+
line=dict(color="black", width=4)
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# Needle center dot
|
| 101 |
+
fig.add_shape(
|
| 102 |
+
type="circle",
|
| 103 |
+
x0=0.48, y0=-0.02,
|
| 104 |
+
x1=0.52, y1=0.02,
|
| 105 |
+
fillcolor="black",
|
| 106 |
+
line=dict(color="black")
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
fig.update_layout(
|
| 110 |
margin=dict(t=30, b=10, l=20, r=20),
|
| 111 |
+
height=220
|
| 112 |
)
|
| 113 |
|
| 114 |
return fig
|
| 115 |
|
| 116 |
|
|
|
|
| 117 |
def analyze_text(text: str, is_ai_generated: bool):
|
| 118 |
text = text.strip()
|
| 119 |
if not text:
|