Spaces:
Running
Running
Adapt to Gradio 6.x API (remove show_download_button, move theme to launch)
Browse files
app.py
CHANGED
|
@@ -12,20 +12,16 @@ from pathlib import Path
|
|
| 12 |
import gradio as gr
|
| 13 |
|
| 14 |
ROOT = Path(__file__).parent
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
REAL_IMGS = sorted(REAL_DIR.glob("*"))
|
| 18 |
-
AI_IMGS = sorted(AI_DIR.glob("*"))
|
| 19 |
|
| 20 |
# Baselines from the GPT4o-Receipt paper (Zhang*, Ren*, et al., 2026)
|
| 21 |
HUMAN_F1 = 0.852
|
| 22 |
-
HUMAN_VISUAL_DELTA = 1.87 # Largest visual discrimination of any evaluator
|
| 23 |
CLAUDE_F1 = 0.975
|
| 24 |
GEMINI_F1 = 0.890
|
| 25 |
|
| 26 |
|
| 27 |
def new_round(state):
|
| 28 |
-
"""Pick one real + one AI, randomize left/right."""
|
| 29 |
real = random.choice(REAL_IMGS)
|
| 30 |
ai = random.choice(AI_IMGS)
|
| 31 |
ai_on_left = random.random() < 0.5
|
|
@@ -38,9 +34,9 @@ def new_round(state):
|
|
| 38 |
str(right),
|
| 39 |
state,
|
| 40 |
gr.update(value="### Which receipt is AI-generated?", visible=True),
|
| 41 |
-
gr.update(visible=True),
|
| 42 |
-
gr.update(visible=True),
|
| 43 |
-
gr.update(visible=False),
|
| 44 |
)
|
| 45 |
|
| 46 |
|
|
@@ -85,33 +81,21 @@ def guess(side, state):
|
|
| 85 |
return (
|
| 86 |
state,
|
| 87 |
gr.update(value=msg, visible=True),
|
| 88 |
-
gr.update(visible=False),
|
| 89 |
-
gr.update(visible=False),
|
| 90 |
-
gr.update(visible=True),
|
| 91 |
)
|
| 92 |
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
return new_round(state)
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
with gr.Blocks(
|
| 100 |
-
title="Spot the AI Receipt — Scam.AI",
|
| 101 |
-
theme=gr.themes.Soft(primary_hue="blue"),
|
| 102 |
-
css="""
|
| 103 |
-
#title { text-align: center; }
|
| 104 |
-
.receipt-img img { object-fit: contain !important; max-height: 500px; }
|
| 105 |
-
""",
|
| 106 |
-
) as demo:
|
| 107 |
gr.Markdown(
|
| 108 |
"# 🧾 Spot the AI Receipt\n"
|
| 109 |
"*One of these receipts is authentic. The other was fully synthesized by "
|
| 110 |
"GPT-4o + GPT-Image-1. Can you tell the difference?*\n\n"
|
| 111 |
"*Built by [Scam.AI](https://www.scam.ai) · Data: "
|
| 112 |
"[gpt4o-receipt](https://huggingface.co/datasets/Scam-AI/gpt4o-receipt) "
|
| 113 |
-
"+ [CORD-v2](https://huggingface.co/datasets/naver-clova-ix/cord-v2)*"
|
| 114 |
-
elem_id="title",
|
| 115 |
)
|
| 116 |
|
| 117 |
state = gr.State({"round": 0, "correct": 0, "total": 0})
|
|
@@ -120,18 +104,15 @@ with gr.Blocks(
|
|
| 120 |
|
| 121 |
with gr.Row():
|
| 122 |
with gr.Column():
|
| 123 |
-
img_l = gr.Image(label="Receipt A",
|
| 124 |
-
interactive=False, show_download_button=False)
|
| 125 |
btn_l = gr.Button("👉 A is the AI", variant="primary", size="lg")
|
| 126 |
with gr.Column():
|
| 127 |
-
img_r = gr.Image(label="Receipt B",
|
| 128 |
-
interactive=False, show_download_button=False)
|
| 129 |
btn_r = gr.Button("👉 B is the AI", variant="primary", size="lg")
|
| 130 |
|
| 131 |
result = gr.Markdown(visible=False)
|
| 132 |
btn_next = gr.Button("→ Next round", variant="secondary", visible=False)
|
| 133 |
|
| 134 |
-
# Wiring
|
| 135 |
btn_l.click(
|
| 136 |
lambda s: guess("left", s),
|
| 137 |
inputs=state,
|
|
@@ -147,10 +128,9 @@ with gr.Blocks(
|
|
| 147 |
outputs=[img_l, img_r, state, prompt, btn_l, btn_r, btn_next],
|
| 148 |
)
|
| 149 |
|
| 150 |
-
# Auto-start on load
|
| 151 |
demo.load(new_round, inputs=state,
|
| 152 |
outputs=[img_l, img_r, state, prompt, btn_l, btn_r, btn_next])
|
| 153 |
|
| 154 |
|
| 155 |
if __name__ == "__main__":
|
| 156 |
-
demo.launch()
|
|
|
|
| 12 |
import gradio as gr
|
| 13 |
|
| 14 |
ROOT = Path(__file__).parent
|
| 15 |
+
REAL_IMGS = sorted((ROOT / "data" / "real").glob("*"))
|
| 16 |
+
AI_IMGS = sorted((ROOT / "data" / "ai").glob("*"))
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Baselines from the GPT4o-Receipt paper (Zhang*, Ren*, et al., 2026)
|
| 19 |
HUMAN_F1 = 0.852
|
|
|
|
| 20 |
CLAUDE_F1 = 0.975
|
| 21 |
GEMINI_F1 = 0.890
|
| 22 |
|
| 23 |
|
| 24 |
def new_round(state):
|
|
|
|
| 25 |
real = random.choice(REAL_IMGS)
|
| 26 |
ai = random.choice(AI_IMGS)
|
| 27 |
ai_on_left = random.random() < 0.5
|
|
|
|
| 34 |
str(right),
|
| 35 |
state,
|
| 36 |
gr.update(value="### Which receipt is AI-generated?", visible=True),
|
| 37 |
+
gr.update(visible=True),
|
| 38 |
+
gr.update(visible=True),
|
| 39 |
+
gr.update(visible=False),
|
| 40 |
)
|
| 41 |
|
| 42 |
|
|
|
|
| 81 |
return (
|
| 82 |
state,
|
| 83 |
gr.update(value=msg, visible=True),
|
| 84 |
+
gr.update(visible=False),
|
| 85 |
+
gr.update(visible=False),
|
| 86 |
+
gr.update(visible=True),
|
| 87 |
)
|
| 88 |
|
| 89 |
|
| 90 |
+
# Gradio 6.x: theme/css moved to launch(); no show_download_button kwarg
|
| 91 |
+
with gr.Blocks(title="Spot the AI Receipt — Scam.AI") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
gr.Markdown(
|
| 93 |
"# 🧾 Spot the AI Receipt\n"
|
| 94 |
"*One of these receipts is authentic. The other was fully synthesized by "
|
| 95 |
"GPT-4o + GPT-Image-1. Can you tell the difference?*\n\n"
|
| 96 |
"*Built by [Scam.AI](https://www.scam.ai) · Data: "
|
| 97 |
"[gpt4o-receipt](https://huggingface.co/datasets/Scam-AI/gpt4o-receipt) "
|
| 98 |
+
"+ [CORD-v2](https://huggingface.co/datasets/naver-clova-ix/cord-v2)*"
|
|
|
|
| 99 |
)
|
| 100 |
|
| 101 |
state = gr.State({"round": 0, "correct": 0, "total": 0})
|
|
|
|
| 104 |
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column():
|
| 107 |
+
img_l = gr.Image(label="Receipt A", interactive=False)
|
|
|
|
| 108 |
btn_l = gr.Button("👉 A is the AI", variant="primary", size="lg")
|
| 109 |
with gr.Column():
|
| 110 |
+
img_r = gr.Image(label="Receipt B", interactive=False)
|
|
|
|
| 111 |
btn_r = gr.Button("👉 B is the AI", variant="primary", size="lg")
|
| 112 |
|
| 113 |
result = gr.Markdown(visible=False)
|
| 114 |
btn_next = gr.Button("→ Next round", variant="secondary", visible=False)
|
| 115 |
|
|
|
|
| 116 |
btn_l.click(
|
| 117 |
lambda s: guess("left", s),
|
| 118 |
inputs=state,
|
|
|
|
| 128 |
outputs=[img_l, img_r, state, prompt, btn_l, btn_r, btn_next],
|
| 129 |
)
|
| 130 |
|
|
|
|
| 131 |
demo.load(new_round, inputs=state,
|
| 132 |
outputs=[img_l, img_r, state, prompt, btn_l, btn_r, btn_next])
|
| 133 |
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
+
demo.launch(theme=gr.themes.Soft(primary_hue="blue"))
|