File size: 1,235 Bytes
ba4f5fa
 
895148c
ba4f5fa
a92a67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446ddfb
a92a67c
 
4827549
a92a67c
 
446ddfb
a92a67c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import warnings
import gradio as gr
import re
import numpy as np

#HF_TOKEN = os.getenv('HW_TOKEN')
#hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")

def sepia(input_img, strength):
    sepia_filter = strength * np.array(
        [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
    ) + (1-strength) * np.identity(3)
    sepia_img = input_img.dot(sepia_filter.T)
    sepia_img /= sepia_img.max()
    return sepia_img

callback = gr.CSVLogger()

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            img_input = gr.Image()
            strength = gr.Slider(0, 1, 0.5)
        img_output = gr.Image()
    with gr.Row():
        btn = gr.Button("Flag")
        
    # This needs to be called at some point prior to the first call to callback.flag()
    callback.setup([img_input, strength, img_output], "flagged_data_points")

    img_input.change(sepia, [img_input, strength], img_output)
    strength.change(sepia, [img_input, strength], img_output)
    
    # We can choose which components to flag -- in this case, we'll flag all of them
    btn.click(lambda *args: callback.flag(args), [img_input, strength, img_output], None, preprocess=False)

demo.launch()