cdactvm commited on
Commit
4827549
1 Parent(s): 7e5a3b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -24
app.py CHANGED
@@ -1,30 +1,32 @@
 
1
  import gradio as gr
2
- from pathlib import Path
3
 
4
- DATA_PATH = Path("./") # Path("/data")
5
- def get_storage():
6
- files = [
7
- {
8
- "orig_name": file.name,
9
- "name": file.resolve(),
10
- "size": file.stat().st_size,
11
- "data": None,
12
- "is_file": True,
13
- }
14
- for file in DATA_PATH.glob("**/*")
15
- if file.is_file()
16
- ]
17
- usage = sum([f['size'] for f in files])
18
- return files, f"{usage/(1024.0 ** 3):.3f}GB"
19
 
20
- with gr.Blocks() as app:
 
 
21
  with gr.Row():
22
  with gr.Column():
23
- btn = gr.Button("Run")
24
- with gr.Column():
25
- files = gr.Files(label="Files")
26
- storage = gr.Text(label="Total Usage")
27
- btn.click(get_storage, inputs=None, outputs=[files, storage], postprocess=False)
 
 
 
 
 
 
 
 
 
28
 
29
- # Files that you explicitly allow on allowed_paths
30
- app.launch(allowed_paths=[str(DATA_PATH)])
 
1
+ import numpy as np
2
  import gradio as gr
 
3
 
4
+ def sepia(input_img, strength):
5
+ sepia_filter = strength * np.array(
6
+ [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
7
+ ) + (1-strength) * np.identity(3)
8
+ sepia_img = input_img.dot(sepia_filter.T)
9
+ sepia_img /= sepia_img.max()
10
+ return sepia_img
 
 
 
 
 
 
 
 
11
 
12
+ callback = gr.CSVLogger()
13
+
14
+ with gr.Blocks() as demo:
15
  with gr.Row():
16
  with gr.Column():
17
+ img_input = gr.Image()
18
+ strength = gr.Slider(0, 1, 0.5)
19
+ img_output = gr.Image()
20
+ with gr.Row():
21
+ btn = gr.Button("Flag")
22
+
23
+ # This needs to be called at some point prior to the first call to callback.flag()
24
+ callback.setup([img_input, strength, img_output], "flagged_data_points")
25
+
26
+ img_input.change(sepia, [img_input, strength], img_output)
27
+ strength.change(sepia, [img_input, strength], img_output)
28
+
29
+ # We can choose which components to flag -- in this case, we'll flag all of them
30
+ btn.click(lambda *args: callback.flag(args), [img_input, strength, img_output], None, preprocess=False)
31
 
32
+ demo.launch()