Spaces:
Running
Running
Upload with huggingface_hub
Browse files- README.md +5 -5
- app.py +33 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: indigo
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.3.1
|
|
|
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
|
4 |
+
emoji: 🔥
|
5 |
colorFrom: indigo
|
6 |
+
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 3.3.1
|
9 |
+
|
10 |
app_file: app.py
|
11 |
pinned: false
|
12 |
---
|
|
|
|
app.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()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
numpy
|