Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdded real image support
app.py
CHANGED
|
@@ -121,12 +121,12 @@ def compute_prompt_match(image: Image.Image, prompt: str) -> float:
|
|
| 121 |
return 0.0
|
| 122 |
|
| 123 |
# --- Main prediction logic ---
|
| 124 |
-
def detect_with_model(image: Image.Image, prompt: str, username: str):
|
| 125 |
if not username.strip():
|
| 126 |
return "Please enter your name.", None, [], gr.update(visible=True), gr.update(visible=False), username
|
| 127 |
|
| 128 |
prompt_score = compute_prompt_match(image, prompt)
|
| 129 |
-
if prompt_score < PROMPT_MATCH_THRESHOLD:
|
| 130 |
message = f"β οΈ Prompt match too low ({round(prompt_score, 2)}%). Please generate an image that better matches the prompt."
|
| 131 |
return message, None, leaderboard, gr.update(visible=True), gr.update(visible=False), username
|
| 132 |
|
|
@@ -144,11 +144,14 @@ def detect_with_model(image: Image.Image, prompt: str, username: str):
|
|
| 144 |
score = 1 if prediction == "Real" else 0
|
| 145 |
|
| 146 |
message = f"π Prediction: {prediction} ({confidence}% confidence)\nπ§ Prompt match: {round(prompt_score, 2)}%"
|
| 147 |
-
if prediction == "Real":
|
| 148 |
leaderboard_scores[username] = leaderboard_scores.get(username, 0) + score
|
| 149 |
message += "\nπ Nice! You fooled the AI. +1 point!"
|
| 150 |
else:
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
save_leaderboard()
|
| 154 |
|
|
@@ -215,7 +218,7 @@ with gr.Blocks(css=".gr-button {font-size: 16px !important}") as demo:
|
|
| 215 |
|
| 216 |
submit_btn.click(
|
| 217 |
fn=detect_with_model,
|
| 218 |
-
inputs=[image_input, prompt_input, username_input],
|
| 219 |
outputs=[
|
| 220 |
prediction_output,
|
| 221 |
image_output,
|
|
|
|
| 121 |
return 0.0
|
| 122 |
|
| 123 |
# --- Main prediction logic ---
|
| 124 |
+
def detect_with_model(image: Image.Image, prompt: str, username: str, model: str):
|
| 125 |
if not username.strip():
|
| 126 |
return "Please enter your name.", None, [], gr.update(visible=True), gr.update(visible=False), username
|
| 127 |
|
| 128 |
prompt_score = compute_prompt_match(image, prompt)
|
| 129 |
+
if prompt_score < PROMPT_MATCH_THRESHOLD and model.lower() != "real":
|
| 130 |
message = f"β οΈ Prompt match too low ({round(prompt_score, 2)}%). Please generate an image that better matches the prompt."
|
| 131 |
return message, None, leaderboard, gr.update(visible=True), gr.update(visible=False), username
|
| 132 |
|
|
|
|
| 144 |
score = 1 if prediction == "Real" else 0
|
| 145 |
|
| 146 |
message = f"π Prediction: {prediction} ({confidence}% confidence)\nπ§ Prompt match: {round(prompt_score, 2)}%"
|
| 147 |
+
if prediction == "Real" and model.lower() != "real":
|
| 148 |
leaderboard_scores[username] = leaderboard_scores.get(username, 0) + score
|
| 149 |
message += "\nπ Nice! You fooled the AI. +1 point!"
|
| 150 |
else:
|
| 151 |
+
if model.lower() == "real":
|
| 152 |
+
message += "\n You uploaded a real image, this does not count toward the leaderboard!"
|
| 153 |
+
else:
|
| 154 |
+
message += "\nπ
The AI caught you this time. Try again!"
|
| 155 |
|
| 156 |
save_leaderboard()
|
| 157 |
|
|
|
|
| 218 |
|
| 219 |
submit_btn.click(
|
| 220 |
fn=detect_with_model,
|
| 221 |
+
inputs=[image_input, prompt_input, username_input, model_input],
|
| 222 |
outputs=[
|
| 223 |
prediction_output,
|
| 224 |
image_output,
|