Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from datetime import datetime
|
|
| 4 |
from typing import List, Dict
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
|
| 8 |
# --------- Heuristic Scoring Logic ---------
|
| 9 |
|
|
@@ -44,6 +45,27 @@ def label_from_score(score: int) -> str:
|
|
| 44 |
return "Low–Medium Trust"
|
| 45 |
return "Low Trust"
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def analyze_text(text: str, is_ai_generated: bool):
|
| 49 |
text = text.strip()
|
|
@@ -237,7 +259,7 @@ def analyze_text(text: str, is_ai_generated: bool):
|
|
| 237 |
Label: **{label}**
|
| 238 |
"""
|
| 239 |
|
| 240 |
-
return overall_md, label, component_md, issues_md, suggestions_md, sentences_md
|
| 241 |
|
| 242 |
|
| 243 |
# --------- Gradio UI ---------
|
|
@@ -273,6 +295,7 @@ This tool estimates a **Trust Score (0–100)** based on:
|
|
| 273 |
analyze_btn = gr.Button("Analyze Credibility", variant="primary")
|
| 274 |
|
| 275 |
with gr.Column():
|
|
|
|
| 276 |
overall_out = gr.Markdown(label="Overall Trust Score")
|
| 277 |
components_out = gr.Markdown(label="Component Breakdown")
|
| 278 |
issues_out = gr.Markdown(label="Issues Detected")
|
|
@@ -280,15 +303,16 @@ This tool estimates a **Trust Score (0–100)** based on:
|
|
| 280 |
sentences_out = gr.Markdown(label="Sentence-level Analysis")
|
| 281 |
|
| 282 |
def gradio_wrapper(text, is_ai_generated):
|
| 283 |
-
overall_md, label, component_md, issues_md, suggestions_md, sentences_md = analyze_text(
|
| 284 |
text, is_ai_generated
|
| 285 |
)
|
| 286 |
-
|
|
|
|
| 287 |
|
| 288 |
analyze_btn.click(
|
| 289 |
fn=gradio_wrapper,
|
| 290 |
inputs=[text_input, is_ai_checkbox],
|
| 291 |
-
outputs=[overall_out, components_out, issues_out, suggestions_out, sentences_out],
|
| 292 |
)
|
| 293 |
|
| 294 |
if __name__ == "__main__":
|
|
|
|
| 4 |
from typing import List, Dict
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
+
import plotly.graph_objects as go
|
| 8 |
|
| 9 |
# --------- Heuristic Scoring Logic ---------
|
| 10 |
|
|
|
|
| 45 |
return "Low–Medium Trust"
|
| 46 |
return "Low Trust"
|
| 47 |
|
| 48 |
+
def make_gauge(score: int):
|
| 49 |
+
fig = go.Figure(
|
| 50 |
+
go.Indicator(
|
| 51 |
+
mode="gauge+number",
|
| 52 |
+
value=score,
|
| 53 |
+
number={"suffix": "%"},
|
| 54 |
+
gauge={
|
| 55 |
+
"axis": {"range": [0, 100]},
|
| 56 |
+
"bar": {"color": "#4f46e5"},
|
| 57 |
+
"steps": [
|
| 58 |
+
{"range": [0, 40], "color": "#fee2e2"}, # red-ish (low)
|
| 59 |
+
{"range": [40, 70], "color": "#fef3c7"}, # yellow (medium)
|
| 60 |
+
{"range": [70, 100], "color": "#dcfce7"} # green (high)
|
| 61 |
+
],
|
| 62 |
+
},
|
| 63 |
+
domain={"x": [0, 1], "y": [0, 1]},
|
| 64 |
+
)
|
| 65 |
+
)
|
| 66 |
+
fig.update_layout(margin=dict(t=0, b=0, l=0, r=0))
|
| 67 |
+
return fig
|
| 68 |
+
|
| 69 |
|
| 70 |
def analyze_text(text: str, is_ai_generated: bool):
|
| 71 |
text = text.strip()
|
|
|
|
| 259 |
Label: **{label}**
|
| 260 |
"""
|
| 261 |
|
| 262 |
+
return overall_int, overall_md, label, component_md, issues_md, suggestions_md, sentences_md
|
| 263 |
|
| 264 |
|
| 265 |
# --------- Gradio UI ---------
|
|
|
|
| 295 |
analyze_btn = gr.Button("Analyze Credibility", variant="primary")
|
| 296 |
|
| 297 |
with gr.Column():
|
| 298 |
+
gauge_plot = gr.Plot(label="trust.AI Score")
|
| 299 |
overall_out = gr.Markdown(label="Overall Trust Score")
|
| 300 |
components_out = gr.Markdown(label="Component Breakdown")
|
| 301 |
issues_out = gr.Markdown(label="Issues Detected")
|
|
|
|
| 303 |
sentences_out = gr.Markdown(label="Sentence-level Analysis")
|
| 304 |
|
| 305 |
def gradio_wrapper(text, is_ai_generated):
|
| 306 |
+
overall_int, overall_md, label, component_md, issues_md, suggestions_md, sentences_md = analyze_text(
|
| 307 |
text, is_ai_generated
|
| 308 |
)
|
| 309 |
+
fig = make_gauge(overall_int)
|
| 310 |
+
return fig, overall_md, component_md, issues_md, suggestions_md, sentences_md
|
| 311 |
|
| 312 |
analyze_btn.click(
|
| 313 |
fn=gradio_wrapper,
|
| 314 |
inputs=[text_input, is_ai_checkbox],
|
| 315 |
+
outputs=[gauge_plot, overall_out, components_out, issues_out, suggestions_out, sentences_out],
|
| 316 |
)
|
| 317 |
|
| 318 |
if __name__ == "__main__":
|