File size: 1,397 Bytes
9aaab47
 
 
179e14c
 
 
 
 
 
 
 
 
 
 
9aaab47
 
 
179e14c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aaab47
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 gradio as gr
from photowithcode import *

def type2im(type):
    path = f'code_images/{type}.png'
    return cv2.imread(path, cv2.IMREAD_COLOR)

def imgproc_1(photo, type, mirror_code):
    print(type)
    code = type2im(type)
    out = photowithcode_proc(photo, code, True, mirror_code)
    return out

def imgproc_2(photo, code, dim_background, mirror_code):
    out = photowithcode_proc(photo, code, dim_background, mirror_code)
    return out

with gr.Blocks() as demo:
    gr.Markdown('Overlay your code on to you photo with this demo.')
    with gr.Tab('Use existing code'):
        with gr.Row():
            with gr.Column():
                input_1 = [gr.Image(), gr.Radio(['Rust', 'C++', 'Python'], value='Rust', label='Choose your programming language'), gr.Checkbox(label='Mirror the code?')]
            with gr.Column():
                output_1 = gr.Image()
        button_1 = gr.Button('Submit')
    with gr.Tab('Use your own code'):
        with gr.Row():
            with gr.Column():
                input_2 = [gr.Image(), gr.Image(), gr.Checkbox(label='Dim the code background?'), gr.Checkbox(label='Mirror the code?')]
            with gr.Column():
                output_2 = gr.Image()
        button_2 = gr.Button('Submit')

    button_1.click(imgproc_1, inputs=input_1, outputs=output_1)
    button_2.click(imgproc_2, inputs=input_2, outputs=output_2)

demo.launch()