mdkhalid commited on
Commit
46061da
·
1 Parent(s): 2589483

multiple gradio examples script

Browse files
Files changed (2) hide show
  1. app.ipynb +12 -24
  2. app.py +136 -3
app.ipynb CHANGED
@@ -396,36 +396,24 @@
396
  },
397
  {
398
  "cell_type": "code",
399
- "execution_count": 23,
 
 
 
 
 
 
 
 
 
400
  "metadata": {},
401
  "outputs": [
402
  {
403
  "name": "stdout",
404
  "output_type": "stream",
405
  "text": [
406
- "usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]\n",
407
- " [--paths] [--json] [--debug]\n",
408
- " [subcommand]\n",
409
- "\n",
410
- "Jupyter: Interactive Computing\n",
411
- "\n",
412
- "positional arguments:\n",
413
- " subcommand the subcommand to launch\n",
414
- "\n",
415
- "options:\n",
416
- " -h, --help show this help message and exit\n",
417
- " --version show the versions of core jupyter packages and exit\n",
418
- " --config-dir show Jupyter config dir\n",
419
- " --data-dir show Jupyter data dir\n",
420
- " --runtime-dir show Jupyter runtime dir\n",
421
- " --paths show all Jupyter paths. Add --json for machine-readable\n",
422
- " format.\n",
423
- " --json output paths as machine-readable json\n",
424
- " --debug output debug information about paths\n",
425
- "\n",
426
- "Available subcommands: kernel kernelspec migrate run troubleshoot\n",
427
- "\n",
428
- "Jupyter command `jupyter-nbconvert` not found.\n"
429
  ]
430
  }
431
  ],
 
396
  },
397
  {
398
  "cell_type": "code",
399
+ "execution_count": null,
400
+ "metadata": {},
401
+ "outputs": [],
402
+ "source": [
403
+ "! pip install nbconvert -U"
404
+ ]
405
+ },
406
+ {
407
+ "cell_type": "code",
408
+ "execution_count": 27,
409
  "metadata": {},
410
  "outputs": [
411
  {
412
  "name": "stdout",
413
  "output_type": "stream",
414
  "text": [
415
+ "[NbConvertApp] Converting notebook app.ipynb to script\n",
416
+ "[NbConvertApp] Writing 2888 bytes to app.py\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  ]
418
  }
419
  ],
app.py CHANGED
@@ -1,7 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
  def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ get_ipython().run_line_magic('load_ext', 'gradio')
8
+
9
+
10
+ # In[4]:
11
+
12
+
13
+ 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')
14
+
15
+
16
+ # In[5]:
17
+
18
+
19
+ 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')
20
+
21
+
22
+ # In[7]:
23
+
24
+
25
  import gradio as gr
26
 
27
  def greet(name):
28
+ return "Hello " + name + "!"
29
+
30
+ demo = gr.Interface(
31
+ fn=greet,
32
+ inputs=gr.Textbox(lines=4, placeholder="Name Here..."),
33
+ outputs="text",
34
+ )
35
+ demo.launch()
36
+
37
+
38
+ # In[15]:
39
+
40
+
41
+ import gradio as gr
42
+
43
+ def greet(yourname, is_morning, temperature):
44
+ salutation = "Good morning" if is_morning else "Good evening"
45
+ greeting = f"{salutation} {name}. It is {temperature} degrees Fahrenheit today."
46
+ celsius = (temperature - 32) * 5 / 9
47
+ return greeting, round(celsius, 2)
48
+
49
+ demo = gr.Interface(
50
+ fn=greet,
51
+ inputs=["text", "checkbox", gr.Slider(-50, 100)],
52
+ outputs=["text", "number"],
53
+ )
54
+ demo.launch()
55
+
56
+
57
+ # In[16]:
58
+
59
+
60
+ import numpy as np
61
+ import gradio as gr
62
+
63
+ def sepia(input_img):
64
+ sepia_filter = np.array([
65
+ [0.393, 0.769, 0.189],
66
+ [0.349, 0.686, 0.168],
67
+ [0.272, 0.534, 0.131]
68
+ ])
69
+ sepia_img = input_img.dot(sepia_filter.T)
70
+ sepia_img /= sepia_img.max()
71
+ return sepia_img
72
+
73
+ demo = gr.Interface(sepia, gr.Image(shape=(200, 200)), "image")
74
+ demo.launch()
75
+
76
+
77
+ # In[18]:
78
+
79
+
80
+ import gradio as gr
81
+
82
+ def greet(name):
83
+ return "Hello " + name + "!"
84
+
85
+ with gr.Blocks() as demo:
86
+ name = gr.Textbox(label="Name")
87
+ output = gr.Textbox(label="Output Box")
88
+ greet_btn = gr.Button("Greet")
89
+ greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
90
+
91
+ demo.launch()
92
+
93
+
94
+ # In[19]:
95
+
96
+
97
+ import numpy as np
98
+ import gradio as gr
99
+
100
+
101
+ def flip_text(x):
102
+ return x[::-1]
103
+
104
+
105
+ def flip_image(x):
106
+ return np.fliplr(x)
107
+
108
+
109
+ with gr.Blocks() as demo:
110
+ gr.Markdown("Flip text or image files using this demo.")
111
+ with gr.Tab("Flip Text"):
112
+ text_input = gr.Textbox()
113
+ text_output = gr.Textbox()
114
+ text_button = gr.Button("Flip")
115
+ with gr.Tab("Flip Image"):
116
+ with gr.Row():
117
+ image_input = gr.Image()
118
+ image_output = gr.Image()
119
+ image_button = gr.Button("Flip")
120
+
121
+ with gr.Accordion("Open for More!"):
122
+ gr.Markdown("Look at me...")
123
+
124
+ text_button.click(flip_text, inputs=text_input, outputs=text_output)
125
+ image_button.click(flip_image, inputs=image_input, outputs=image_output)
126
+
127
+ demo.launch()
128
+
129
+
130
+ # In[26]:
131
+
132
+
133
+ get_ipython().system(' pip install nbconvert -U')
134
+
135
+
136
+ # In[27]:
137
+
138
+
139
+ get_ipython().system('jupyter nbconvert --to script app.ipynb')
140