dropbop commited on
Commit
13eef3f
·
verified ·
1 Parent(s): 2a6e97e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -5,7 +5,6 @@ import random
5
  import pandas as pd
6
  import os
7
  from itertools import islice
8
- import json
9
  import pyarrow as pa
10
  import pyarrow.parquet as pq
11
 
@@ -57,7 +56,7 @@ def get_next_image():
57
  shuffled_chunk = []
58
  chunk_iter = None
59
 
60
- def rate_image(image_id, bounds, rating):
61
  global labels_list
62
 
63
  labels_list.append(
@@ -65,7 +64,7 @@ def rate_image(image_id, bounds, rating):
65
  "image_id": image_id,
66
  "bounds": bounds,
67
  "rating": rating,
68
- "google_maps_link": "", # Adding google maps link to the data to be downloaded
69
  }
70
  )
71
 
@@ -74,11 +73,14 @@ def rate_image(image_id, bounds, rating):
74
 
75
  def save_labels():
76
  global labels_list
77
- table = pa.Table.from_pylist(labels_list)
78
- pq.write_table(table, "labeled_data.parquet")
79
- return "labeled_data.parquet"
80
-
81
- # Gradio interface
 
 
 
82
  with gr.Blocks() as iface:
83
  with gr.Row():
84
  with gr.Column():
@@ -88,13 +90,14 @@ with gr.Blocks() as iface:
88
  google_maps_link_out = gr.Textbox(label="Google Maps Link", visible=True)
89
  with gr.Column():
90
  rating_radio = gr.Radio(["Cool", "Not Cool"], label="Rating")
91
- submit_button = gr.Button("Submit Rating")
92
- download_button = gr.Button("Download Labels")
 
93
  download_file = gr.File(label="Download")
94
 
95
  submit_button.click(
96
  rate_image,
97
- inputs=[image_id_out, bounds_out, rating_radio],
98
  outputs=[image_out, image_id_out, bounds_out, google_maps_link_out]
99
  )
100
 
 
5
  import pandas as pd
6
  import os
7
  from itertools import islice
 
8
  import pyarrow as pa
9
  import pyarrow.parquet as pq
10
 
 
56
  shuffled_chunk = []
57
  chunk_iter = None
58
 
59
+ def rate_image(image_id, bounds, rating, google_maps_link):
60
  global labels_list
61
 
62
  labels_list.append(
 
64
  "image_id": image_id,
65
  "bounds": bounds,
66
  "rating": rating,
67
+ "google_maps_link": google_maps_link,
68
  }
69
  )
70
 
 
73
 
74
  def save_labels():
75
  global labels_list
76
+ if labels_list:
77
+ table = pa.Table.from_pylist(labels_list)
78
+ pq.write_table(table, "labeled_data.parquet")
79
+ return "labeled_data.parquet"
80
+ else:
81
+ return None
82
+
83
+ # Gradio interface
84
  with gr.Blocks() as iface:
85
  with gr.Row():
86
  with gr.Column():
 
90
  google_maps_link_out = gr.Textbox(label="Google Maps Link", visible=True)
91
  with gr.Column():
92
  rating_radio = gr.Radio(["Cool", "Not Cool"], label="Rating")
93
+ with gr.Row():
94
+ submit_button = gr.Button("Submit Rating")
95
+ download_button = gr.Button("Download Labels")
96
  download_file = gr.File(label="Download")
97
 
98
  submit_button.click(
99
  rate_image,
100
+ inputs=[image_id_out, bounds_out, rating_radio, google_maps_link_out],
101
  outputs=[image_out, image_id_out, bounds_out, google_maps_link_out]
102
  )
103