aliabd HF Staff commited on
Commit
01837fe
·
1 Parent(s): 548da1c

Upload with huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +6 -7
  2. requirements.txt +1 -0
  3. run.py +33 -0
README.md CHANGED
@@ -1,12 +1,11 @@
 
1
  ---
2
- title: Blocks Flag Main
3
- emoji:
4
- colorFrom: blue
5
- colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.6
8
- app_file: app.py
9
  pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: blocks_flag_main
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.6
9
+ app_file: run.py
10
  pinned: false
11
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ numpyhttps://gradio-main-build.s3.amazonaws.com/c3bec6153737855510542e8154391f328ac72606/gradio-3.6-py3-none-any.whl
run.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if __name__ == "__main__":
33
+ demo.launch()