yonatanbitton commited on
Commit
05be506
·
1 Parent(s): 971adc5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from datasets import load_dataset
4
+
5
+ auth_token = os.environ.get("auth_token")
6
+ visit_bench = load_dataset("mlfoundations/visit-bench", use_auth_token=auth_token)['test']
7
+
8
+ df = visit_bench.to_pandas()
9
+ print(f"Got {len(df)} items in dataframe")
10
+ df = df.sample(frac=1)
11
+
12
+ LINES_NUMBER = 20
13
+
14
+ def display_df():
15
+ df_images = df.head(LINES_NUMBER)
16
+ return df_images
17
+
18
+ def display_next(dataframe, end):
19
+ start = int(end or len(dataframe))
20
+ end = int(start) + int(LINES_NUMBER)
21
+ global df
22
+ if end >= len(df) - 1:
23
+ start = 0
24
+ end = LINES_NUMBER
25
+ df = df.sample(frac=1)
26
+ print(f"Shuffle")
27
+ df_images = df.iloc[start:end]
28
+ assert len(df_images) == LINES_NUMBER
29
+ return df_images, end
30
+
31
+ initial_dataframe = display_df()
32
+
33
+ # Gradio Blocks
34
+ with gr.Blocks() as demo:
35
+ gr.Markdown("<h1><center>VisIT-Bench Dataset Viewer</center></h1>")
36
+
37
+ with gr.Row():
38
+ num_end = gr.Number(visible=False)
39
+ b1 = gr.Button("Get Initial dataframe")
40
+ b2 = gr.Button("Next Rows")
41
+
42
+ with gr.Row():
43
+ out_dataframe = gr.Dataframe(initial_dataframe, wrap=True, max_rows=LINES_NUMBER, overflow_row_behaviour="paginate",
44
+ interactive=False)
45
+
46
+ b1.click(fn=display_df, outputs=out_dataframe, api_name="initial_dataframe")
47
+ b2.click(fn=display_next, inputs=[out_dataframe, num_end], outputs=[out_dataframe, num_end],
48
+ api_name="next_rows")
49
+
50
+ demo.launch(debug=True, show_error=True)