File size: 2,900 Bytes
46061da
 
 
 
 
 
d308002
46061da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85c70ad
 
 
46061da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d308002
46061da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d308002
46061da
 
 
 
 
d308002
85c70ad
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
# coding: utf-8

# In[1]:


'''get_ipython().run_line_magic('load_ext', 'gradio')


# In[4]:


get_ipython().run_cell_magic('blocks', '', '\nimport gradio as gr\n\ngr.Markdown("# Greetings from Gradio!")\ninp = gr.Textbox(placeholder="What is your name?")\nout = gr.Textbox()\n\ninp.change(fn=lambda x: f"Welcome, {x}!", \n           inputs=inp, \n           outputs=out)\n')


# In[5]:


get_ipython().run_cell_magic('blocks', '', 'def greet(name):\n    return "Hello " + name + "!"\n\ndemo = gr.Interface(fn=greet, inputs="text", outputs="text")\n    \ndemo.launch()  \n')


# In[7]:


import gradio as gr

def greet(name):
    return "Hello " + name + "!"

demo = gr.Interface(
    fn=greet,
    inputs=gr.Textbox(lines=4, placeholder="Name Here..."),
    outputs="text",
)
demo.launch()


# In[15]:


import gradio as gr

def greet(yourname, is_morning, temperature):
    salutation = "Good morning" if is_morning else "Good evening"
    greeting = f"{salutation} {name}. It is {temperature} degrees Fahrenheit today."
    celsius = (temperature - 32) * 5 / 9
    return greeting, round(celsius, 2)

demo = gr.Interface(
    fn=greet,
    inputs=["text", "checkbox", gr.Slider(-50, 100)],
    outputs=["text", "number"],
)
demo.launch()


# In[16]:


import numpy as np
import gradio as gr

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

demo = gr.Interface(sepia, gr.Image(shape=(200, 200)), "image")
demo.launch()


# In[18]:


import gradio as gr

def greet(name):
    return "Hello " + name + "!"

with gr.Blocks() as demo:
    name = gr.Textbox(label="Name")
    output = gr.Textbox(label="Output Box")
    greet_btn = gr.Button("Greet")
    greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")

demo.launch()'''


# In[19]:


import numpy as np
import gradio as gr


def flip_text(x):
    return x[::-1]


def flip_image(x):
    return np.fliplr(x)


with gr.Blocks() as demo:
    gr.Markdown("Flip text or image files using this demo.")
    with gr.Tab("Flip Text"):
        text_input = gr.Textbox()
        text_output = gr.Textbox()
        text_button = gr.Button("Flip")
    with gr.Tab("Flip Image"):
        with gr.Row():
            image_input = gr.Image()
            image_output = gr.Image()
        image_button = gr.Button("Flip")

    with gr.Accordion("Open for More!"):
        gr.Markdown("Look at me...")

    text_button.click(flip_text, inputs=text_input, outputs=text_output)
    image_button.click(flip_image, inputs=image_input, outputs=image_output)

demo.launch()


# In[26]:


'''get_ipython().system(' pip install nbconvert -U')


# In[27]:


get_ipython().system('jupyter nbconvert --to script app.ipynb')'''