Spaces:
Runtime error
Runtime error
Jonas Rheiner
commited on
Commit
·
a14cce9
1
Parent(s):
8d0eae7
Randomly shuffle versus images
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import plotly.graph_objects as go
|
|
| 8 |
import hashlib
|
| 9 |
from PIL import Image
|
| 10 |
import json
|
|
|
|
| 11 |
|
| 12 |
os.environ["PYTHONHASHSEED"] = "42"
|
| 13 |
|
|
@@ -291,17 +292,6 @@ country_to_center_coords = {
|
|
| 291 |
"United States": (39.7837304, -100.445882),
|
| 292 |
}
|
| 293 |
|
| 294 |
-
INTIAL_VERSUS_IMAGE = "versus_images/Europe_Germany_49.069183_10.319444_im2gps3k.jpg"
|
| 295 |
-
INITAL_VERSUS_STATE = {
|
| 296 |
-
"image": INTIAL_VERSUS_IMAGE,
|
| 297 |
-
"continent": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[0],
|
| 298 |
-
"country": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[1],
|
| 299 |
-
"lat": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[2],
|
| 300 |
-
"lon": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[3],
|
| 301 |
-
"score": {"HUMAN": 0, "AI": 0},
|
| 302 |
-
"idx": 0,
|
| 303 |
-
}
|
| 304 |
-
|
| 305 |
|
| 306 |
def predict(input_img):
|
| 307 |
inputs = processor(
|
|
@@ -504,11 +494,7 @@ def get_example_images(dir):
|
|
| 504 |
|
| 505 |
|
| 506 |
def next_versus_image(versus_state):
|
| 507 |
-
|
| 508 |
-
versus_state["idx"] += 1
|
| 509 |
-
if versus_state["idx"] > len(images):
|
| 510 |
-
versus_state["idx"] = 0
|
| 511 |
-
versus_image = images[versus_state["idx"]]
|
| 512 |
versus_state["continent"] = versus_image.split("/")[-1].split("_")[0]
|
| 513 |
versus_state["country"] = versus_image.split("/")[-1].split("_")[1]
|
| 514 |
versus_state["lat"] = versus_image.split("/")[-1].split("_")[2]
|
|
@@ -528,6 +514,20 @@ for img_path in example_images:
|
|
| 528 |
"lon": img_path.split("/")[-1].split("_")[3],
|
| 529 |
}
|
| 530 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
demo = gr.Blocks(title="Thesis Demo")
|
| 532 |
with demo:
|
| 533 |
gr.HTML(
|
|
@@ -573,10 +573,10 @@ with demo:
|
|
| 573 |
)
|
| 574 |
|
| 575 |
with gr.Tab("Versus Mode"):
|
| 576 |
-
versus_state = gr.State(value=
|
| 577 |
with gr.Row():
|
| 578 |
with gr.Column():
|
| 579 |
-
versus_image = gr.Image(
|
| 580 |
continent_selection = gr.Radio(
|
| 581 |
continents,
|
| 582 |
label="Continents",
|
|
|
|
| 8 |
import hashlib
|
| 9 |
from PIL import Image
|
| 10 |
import json
|
| 11 |
+
import random
|
| 12 |
|
| 13 |
os.environ["PYTHONHASHSEED"] = "42"
|
| 14 |
|
|
|
|
| 292 |
"United States": (39.7837304, -100.445882),
|
| 293 |
}
|
| 294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
def predict(input_img):
|
| 297 |
inputs = processor(
|
|
|
|
| 494 |
|
| 495 |
|
| 496 |
def next_versus_image(versus_state):
|
| 497 |
+
versus_image = random.sample(versus_state["images"], 1)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
versus_state["continent"] = versus_image.split("/")[-1].split("_")[0]
|
| 499 |
versus_state["country"] = versus_image.split("/")[-1].split("_")[1]
|
| 500 |
versus_state["lat"] = versus_image.split("/")[-1].split("_")[2]
|
|
|
|
| 514 |
"lon": img_path.split("/")[-1].split("_")[3],
|
| 515 |
}
|
| 516 |
|
| 517 |
+
def set_up_intial_state():
|
| 518 |
+
INTIAL_VERSUS_IMAGE = "versus_images/Europe_Germany_49.069183_10.319444_im2gps3k.jpg"
|
| 519 |
+
INITAL_VERSUS_STATE = {
|
| 520 |
+
"image": INTIAL_VERSUS_IMAGE,
|
| 521 |
+
"continent": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[0],
|
| 522 |
+
"country": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[1],
|
| 523 |
+
"lat": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[2],
|
| 524 |
+
"lon": INTIAL_VERSUS_IMAGE.split("/")[-1].split("_")[3],
|
| 525 |
+
"score": {"HUMAN": 0, "AI": 0},
|
| 526 |
+
"images": get_example_images("versus_images")
|
| 527 |
+
}
|
| 528 |
+
return INITAL_VERSUS_STATE
|
| 529 |
+
|
| 530 |
+
|
| 531 |
demo = gr.Blocks(title="Thesis Demo")
|
| 532 |
with demo:
|
| 533 |
gr.HTML(
|
|
|
|
| 573 |
)
|
| 574 |
|
| 575 |
with gr.Tab("Versus Mode"):
|
| 576 |
+
versus_state = gr.State(value=set_up_intial_state())
|
| 577 |
with gr.Row():
|
| 578 |
with gr.Column():
|
| 579 |
+
versus_image = gr.Image(versus_state.value["image"], interactive=False, show_download_button=False, show_share_button=False, show_fullscreen_button=True)
|
| 580 |
continent_selection = gr.Radio(
|
| 581 |
continents,
|
| 582 |
label="Continents",
|
versus_images/{Asia_China_31.2389_121.4851_im2gps.jpg → Asia_Hong Kong_31.2389_121.4851_im2gps.jpg}
RENAMED
|
File without changes
|