axiom-coding-agent-setup 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.agents/skills/agent-browser/SKILL.md +55 -0
  2. package/.agents/skills/developing-with-streamlit/SKILL.md +220 -0
  3. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-chat-ui/SKILL.md +195 -0
  4. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/SKILL.md +233 -0
  5. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/packaged-components.md +212 -0
  6. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/state-sync.md +149 -0
  7. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/theme-css-variables.md +243 -0
  8. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/troubleshooting.md +121 -0
  9. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-dashboards/SKILL.md +147 -0
  10. package/.agents/skills/developing-with-streamlit/skills/building-streamlit-multipage-apps/SKILL.md +218 -0
  11. package/.agents/skills/developing-with-streamlit/skills/choosing-streamlit-selection-widgets/SKILL.md +139 -0
  12. package/.agents/skills/developing-with-streamlit/skills/connecting-streamlit-to-snowflake/SKILL.md +188 -0
  13. package/.agents/skills/developing-with-streamlit/skills/creating-streamlit-themes/SKILL.md +486 -0
  14. package/.agents/skills/developing-with-streamlit/skills/displaying-streamlit-data/SKILL.md +199 -0
  15. package/.agents/skills/developing-with-streamlit/skills/improving-streamlit-design/SKILL.md +191 -0
  16. package/.agents/skills/developing-with-streamlit/skills/optimizing-streamlit-performance/SKILL.md +323 -0
  17. package/.agents/skills/developing-with-streamlit/skills/organizing-streamlit-code/SKILL.md +91 -0
  18. package/.agents/skills/developing-with-streamlit/skills/setting-up-streamlit-environment/SKILL.md +128 -0
  19. package/.agents/skills/developing-with-streamlit/skills/using-streamlit-cli/SKILL.md +165 -0
  20. package/.agents/skills/developing-with-streamlit/skills/using-streamlit-custom-components/SKILL.md +170 -0
  21. package/.agents/skills/developing-with-streamlit/skills/using-streamlit-layouts/SKILL.md +229 -0
  22. package/.agents/skills/developing-with-streamlit/skills/using-streamlit-markdown/SKILL.md +207 -0
  23. package/.agents/skills/developing-with-streamlit/skills/using-streamlit-session-state/SKILL.md +144 -0
  24. package/.agents/skills/developing-with-streamlit/templates/.gitattributes +3 -0
  25. package/.agents/skills/developing-with-streamlit/templates/apps/README.md +188 -0
  26. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-companies/pyproject.toml +12 -0
  27. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-companies/streamlit_app.py +365 -0
  28. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute/pyproject.toml +12 -0
  29. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute/streamlit_app.py +461 -0
  30. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/.streamlit/secrets.toml.example +20 -0
  31. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/pyproject.toml +11 -0
  32. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/snowflake.yml +18 -0
  33. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/streamlit_app.py +527 -0
  34. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-feature-usage/pyproject.toml +12 -0
  35. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-feature-usage/streamlit_app.py +307 -0
  36. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics/pyproject.toml +12 -0
  37. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics/streamlit_app.py +426 -0
  38. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/.streamlit/secrets.toml.example +20 -0
  39. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/pyproject.toml +11 -0
  40. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/snowflake.yml +18 -0
  41. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/streamlit_app.py +463 -0
  42. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-seattle-weather/pyproject.toml +12 -0
  43. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-seattle-weather/streamlit_app.py +252 -0
  44. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers/pyproject.toml +12 -0
  45. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers/streamlit_app.py +342 -0
  46. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/.streamlit/secrets.toml.example +20 -0
  47. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/pyproject.toml +11 -0
  48. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/snowflake.yml +18 -0
  49. package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/streamlit_app.py +384 -0
  50. package/.agents/skills/developing-with-streamlit/templates/themes/README.md +128 -0
  51. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/dracula.toml +39 -0
  52. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/github.toml +37 -0
  53. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/minimal.toml +39 -0
  54. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/nord.toml +39 -0
  55. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/snowflake.toml +42 -0
  56. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/solarized-light.toml +38 -0
  57. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/spotify.toml +34 -0
  58. package/.agents/skills/developing-with-streamlit/templates/themes/_configs/stripe.toml +35 -0
  59. package/.agents/skills/developing-with-streamlit/templates/themes/_shared/streamlit_app.py +336 -0
  60. package/.agents/skills/developing-with-streamlit/templates/themes/_templates/pyproject.toml.tmpl +12 -0
  61. package/.agents/skills/developing-with-streamlit/templates/themes/dracula/.streamlit/config.toml +39 -0
  62. package/.agents/skills/developing-with-streamlit/templates/themes/dracula/pyproject.toml +10 -0
  63. package/.agents/skills/developing-with-streamlit/templates/themes/dracula/streamlit_app.py +337 -0
  64. package/.agents/skills/developing-with-streamlit/templates/themes/github/.streamlit/config.toml +37 -0
  65. package/.agents/skills/developing-with-streamlit/templates/themes/github/pyproject.toml +10 -0
  66. package/.agents/skills/developing-with-streamlit/templates/themes/github/streamlit_app.py +337 -0
  67. package/.agents/skills/developing-with-streamlit/templates/themes/manage.py +332 -0
  68. package/.agents/skills/developing-with-streamlit/templates/themes/minimal/.streamlit/config.toml +39 -0
  69. package/.agents/skills/developing-with-streamlit/templates/themes/minimal/pyproject.toml +10 -0
  70. package/.agents/skills/developing-with-streamlit/templates/themes/minimal/streamlit_app.py +337 -0
  71. package/.agents/skills/developing-with-streamlit/templates/themes/nord/.streamlit/config.toml +39 -0
  72. package/.agents/skills/developing-with-streamlit/templates/themes/nord/pyproject.toml +10 -0
  73. package/.agents/skills/developing-with-streamlit/templates/themes/nord/streamlit_app.py +337 -0
  74. package/.agents/skills/developing-with-streamlit/templates/themes/snowflake/.streamlit/config.toml +42 -0
  75. package/.agents/skills/developing-with-streamlit/templates/themes/snowflake/pyproject.toml +10 -0
  76. package/.agents/skills/developing-with-streamlit/templates/themes/snowflake/streamlit_app.py +337 -0
  77. package/.agents/skills/developing-with-streamlit/templates/themes/solarized-light/.streamlit/config.toml +38 -0
  78. package/.agents/skills/developing-with-streamlit/templates/themes/solarized-light/pyproject.toml +10 -0
  79. package/.agents/skills/developing-with-streamlit/templates/themes/solarized-light/streamlit_app.py +337 -0
  80. package/.agents/skills/developing-with-streamlit/templates/themes/spotify/.streamlit/config.toml +34 -0
  81. package/.agents/skills/developing-with-streamlit/templates/themes/spotify/pyproject.toml +10 -0
  82. package/.agents/skills/developing-with-streamlit/templates/themes/spotify/streamlit_app.py +337 -0
  83. package/.agents/skills/developing-with-streamlit/templates/themes/stripe/.streamlit/config.toml +35 -0
  84. package/.agents/skills/developing-with-streamlit/templates/themes/stripe/pyproject.toml +10 -0
  85. package/.agents/skills/developing-with-streamlit/templates/themes/stripe/streamlit_app.py +337 -0
  86. package/.agents/skills/fastapi/SKILL.md +436 -0
  87. package/.agents/skills/fastapi/references/dependencies.md +142 -0
  88. package/.agents/skills/fastapi/references/other-tools.md +76 -0
  89. package/.agents/skills/fastapi/references/streaming.md +105 -0
  90. package/.agents/skills/frontend-design/LICENSE.txt +177 -0
  91. package/.agents/skills/frontend-design/SKILL.md +42 -0
  92. package/.agents/skills/gradio/SKILL.md +84 -0
  93. package/.agents/skills/gradio/references/api-signatures.md +115 -0
  94. package/.agents/skills/gradio/references/event-listeners.md +130 -0
  95. package/.agents/skills/gradio/references/examples.md +613 -0
  96. package/.agents/skills/ui-ux-pro-max/SKILL.md +659 -0
  97. package/.agents/skills/ui-ux-pro-max/data +1 -0
  98. package/.agents/skills/ui-ux-pro-max/scripts +1 -0
  99. package/.env.axiom +8 -0
  100. package/AGENTS.md +2 -1
  101. package/README.md +19 -3
  102. package/bin/cli.js +11 -1
  103. package/opencode.json +7 -4
  104. package/package.json +1 -1
  105. package/skills-lock.json +36 -0
  106. package/.agents/skills/n8n-patterns/SKILL.md +0 -272
@@ -0,0 +1,613 @@
1
+ # Gradio End-to-End Examples
2
+
3
+ Complete working Gradio apps for reference.
4
+
5
+ ## Blocks Essay Simple
6
+
7
+ ```python
8
+ import gradio as gr
9
+
10
+ def change_textbox(choice):
11
+ if choice == "short":
12
+ return gr.Textbox(lines=2, visible=True)
13
+ elif choice == "long":
14
+ return gr.Textbox(lines=8, visible=True, value="Lorem ipsum dolor sit amet")
15
+ else:
16
+ return gr.Textbox(visible=False)
17
+
18
+ with gr.Blocks() as demo:
19
+ radio = gr.Radio(
20
+ ["short", "long", "none"], label="What kind of essay would you like to write?"
21
+ )
22
+ text = gr.Textbox(lines=2, interactive=True, buttons=["copy"])
23
+ radio.change(fn=change_textbox, inputs=radio, outputs=text)
24
+
25
+ demo.launch()
26
+ ```
27
+
28
+ ## Blocks Flipper
29
+
30
+ ```python
31
+ import numpy as np
32
+ import gradio as gr
33
+
34
+ def flip_text(x):
35
+ return x[::-1]
36
+
37
+ def flip_image(x):
38
+ return np.fliplr(x)
39
+
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown("Flip text or image files using this demo.")
42
+ with gr.Tab("Flip Text"):
43
+ text_input = gr.Textbox()
44
+ text_output = gr.Textbox()
45
+ text_button = gr.Button("Flip")
46
+ with gr.Tab("Flip Image"):
47
+ with gr.Row():
48
+ image_input = gr.Image()
49
+ image_output = gr.Image()
50
+ image_button = gr.Button("Flip")
51
+
52
+ with gr.Accordion("Open for More!", open=False):
53
+ gr.Markdown("Look at me...")
54
+ temp_slider = gr.Slider(
55
+ 0, 1,
56
+ value=0.1,
57
+ step=0.1,
58
+ interactive=True,
59
+ label="Slide me",
60
+ )
61
+
62
+ text_button.click(flip_text, inputs=text_input, outputs=text_output)
63
+ image_button.click(flip_image, inputs=image_input, outputs=image_output)
64
+
65
+ demo.launch()
66
+ ```
67
+
68
+ ## Blocks Form
69
+
70
+ ```python
71
+ import gradio as gr
72
+
73
+ with gr.Blocks() as demo:
74
+ name_box = gr.Textbox(label="Name")
75
+ age_box = gr.Number(label="Age", minimum=0, maximum=100)
76
+ symptoms_box = gr.CheckboxGroup(["Cough", "Fever", "Runny Nose"])
77
+ submit_btn = gr.Button("Submit")
78
+
79
+ with gr.Column(visible=False) as output_col:
80
+ diagnosis_box = gr.Textbox(label="Diagnosis")
81
+ patient_summary_box = gr.Textbox(label="Patient Summary")
82
+
83
+ def submit(name, age, symptoms):
84
+ return {
85
+ submit_btn: gr.Button(visible=False),
86
+ output_col: gr.Column(visible=True),
87
+ diagnosis_box: "covid" if "Cough" in symptoms else "flu",
88
+ patient_summary_box: f"{name}, {age} y/o",
89
+ }
90
+
91
+ submit_btn.click(
92
+ submit,
93
+ [name_box, age_box, symptoms_box],
94
+ [submit_btn, diagnosis_box, patient_summary_box, output_col],
95
+ )
96
+
97
+ demo.launch()
98
+ ```
99
+
100
+ ## Blocks Hello
101
+
102
+ ```python
103
+ import gradio as gr
104
+
105
+ def welcome(name):
106
+ return f"Welcome to Gradio, {name}!"
107
+
108
+ with gr.Blocks() as demo:
109
+ gr.Markdown(
110
+ """
111
+ # Hello World!
112
+ Start typing below to see the output.
113
+ """)
114
+ inp = gr.Textbox(placeholder="What is your name?")
115
+ out = gr.Textbox()
116
+ inp.change(welcome, inp, out)
117
+
118
+ demo.launch()
119
+ ```
120
+
121
+ ## Blocks Layout
122
+
123
+ ```python
124
+ import gradio as gr
125
+
126
+ demo = gr.Blocks()
127
+
128
+ with demo:
129
+ with gr.Row():
130
+ gr.Image(interactive=True, scale=2)
131
+ gr.Image()
132
+ with gr.Row():
133
+ gr.Textbox(label="Text")
134
+ gr.Number(label="Count", scale=2)
135
+ gr.Radio(choices=["One", "Two"])
136
+ with gr.Row():
137
+ gr.Button("500", scale=0, min_width=500)
138
+ gr.Button("A", scale=0)
139
+ gr.Button("grow")
140
+ with gr.Row():
141
+ gr.Textbox()
142
+ gr.Textbox()
143
+ gr.Button()
144
+ with gr.Row():
145
+ with gr.Row():
146
+ with gr.Column():
147
+ gr.Textbox(label="Text")
148
+ gr.Number(label="Count")
149
+ gr.Radio(choices=["One", "Two"])
150
+ gr.Image()
151
+ with gr.Column():
152
+ gr.Image(interactive=True)
153
+ gr.Image()
154
+ gr.Image()
155
+ gr.Textbox(label="Text")
156
+ gr.Number(label="Count")
157
+ gr.Radio(choices=["One", "Two"])
158
+
159
+ demo.launch()
160
+ ```
161
+
162
+ ## Calculator
163
+
164
+ ```python
165
+ import gradio as gr
166
+
167
+ def calculator(num1, operation, num2):
168
+ if operation == "add":
169
+ return num1 + num2
170
+ elif operation == "subtract":
171
+ return num1 - num2
172
+ elif operation == "multiply":
173
+ return num1 * num2
174
+ elif operation == "divide":
175
+ if num2 == 0:
176
+ raise gr.Error("Cannot divide by zero!")
177
+ return num1 / num2
178
+
179
+ demo = gr.Interface(
180
+ calculator,
181
+ [
182
+ "number",
183
+ gr.Radio(["add", "subtract", "multiply", "divide"]),
184
+ "number"
185
+ ],
186
+ "number",
187
+ examples=[
188
+ [45, "add", 3],
189
+ [3.14, "divide", 2],
190
+ [144, "multiply", 2.5],
191
+ [0, "subtract", 1.2],
192
+ ],
193
+ title="Toy Calculator",
194
+ description="Here's a sample toy calculator.",
195
+ api_name="predict"
196
+ )
197
+
198
+ demo.launch()
199
+ ```
200
+
201
+ ## Chatbot Simple
202
+
203
+ ```python
204
+ import gradio as gr
205
+ import random
206
+ import time
207
+
208
+ with gr.Blocks() as demo:
209
+ chatbot = gr.Chatbot()
210
+ msg = gr.Textbox()
211
+ clear = gr.ClearButton([msg, chatbot])
212
+
213
+ def respond(message, chat_history):
214
+ bot_message = random.choice(["How are you?", "Today is a great day", "I'm very hungry"])
215
+ chat_history.append({"role": "user", "content": message})
216
+ chat_history.append({"role": "assistant", "content": bot_message})
217
+ time.sleep(2)
218
+ return "", chat_history
219
+
220
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
221
+
222
+ demo.launch()
223
+ ```
224
+
225
+ ## Chatbot Streaming
226
+
227
+ ```python
228
+ import gradio as gr
229
+ import random
230
+ import time
231
+
232
+ with gr.Blocks() as demo:
233
+ chatbot = gr.Chatbot()
234
+ msg = gr.Textbox()
235
+ clear = gr.Button("Clear")
236
+
237
+ def user(user_message, history: list):
238
+ return "", history + [{"role": "user", "content": user_message}]
239
+
240
+ def bot(history: list):
241
+ bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
242
+ history.append({"role": "assistant", "content": ""})
243
+ for character in bot_message:
244
+ history[-1]['content'] += character
245
+ time.sleep(0.05)
246
+ yield history
247
+
248
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
249
+ bot, chatbot, chatbot
250
+ )
251
+ clear.click(lambda: None, None, chatbot, queue=False)
252
+
253
+ demo.launch()
254
+ ```
255
+
256
+ ## Custom Css
257
+
258
+ ```python
259
+ import gradio as gr
260
+
261
+ with gr.Blocks() as demo:
262
+ with gr.Column(elem_classes="cool-col"):
263
+ gr.Markdown("### Gradio Demo with Custom CSS", elem_classes="darktest")
264
+ gr.Markdown(
265
+ elem_classes="markdown",
266
+ value="Resize the browser window to see the CSS media query in action.",
267
+ )
268
+
269
+ if __name__ == "__main__":
270
+ demo.launch(css_paths=["demo/custom_css/custom_css.css"])
271
+ ```
272
+
273
+ ## Fake Diffusion
274
+
275
+ ```python
276
+ import gradio as gr
277
+ import numpy as np
278
+ import time
279
+
280
+ def fake_diffusion(steps):
281
+ rng = np.random.default_rng()
282
+ for i in range(steps):
283
+ time.sleep(1)
284
+ image = rng.random(size=(600, 600, 3))
285
+ yield image
286
+ image = np.ones((1000,1000,3), np.uint8)
287
+ image[:] = [255, 124, 0]
288
+ yield image
289
+
290
+ demo = gr.Interface(fake_diffusion,
291
+ inputs=gr.Slider(1, 10, 3, step=1),
292
+ outputs="image",
293
+ api_name="predict")
294
+
295
+ demo.launch()
296
+ ```
297
+
298
+ ## Hello World
299
+
300
+ ```python
301
+ import gradio as gr
302
+
303
+
304
+ def greet(name):
305
+ return "Hello " + name + "!"
306
+
307
+
308
+ demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox", api_name="predict")
309
+
310
+ demo.launch()
311
+ ```
312
+
313
+ ## Image Editor
314
+
315
+ ```python
316
+ import gradio as gr
317
+ import time
318
+
319
+
320
+ def sleep(im):
321
+ time.sleep(5)
322
+ return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
323
+
324
+
325
+ def predict(im):
326
+ return im["composite"]
327
+
328
+
329
+ with gr.Blocks() as demo:
330
+ with gr.Row():
331
+ im = gr.ImageEditor(
332
+ type="numpy",
333
+ )
334
+ im_preview = gr.Image()
335
+ n_upload = gr.Number(0, label="Number of upload events", step=1)
336
+ n_change = gr.Number(0, label="Number of change events", step=1)
337
+ n_input = gr.Number(0, label="Number of input events", step=1)
338
+
339
+ im.upload(lambda x: x + 1, outputs=n_upload, inputs=n_upload)
340
+ im.change(lambda x: x + 1, outputs=n_change, inputs=n_change)
341
+ im.input(lambda x: x + 1, outputs=n_input, inputs=n_input)
342
+ im.change(predict, outputs=im_preview, inputs=im, show_progress="hidden")
343
+
344
+ demo.launch()
345
+ ```
346
+
347
+ ## On Listener Decorator
348
+
349
+ ```python
350
+ import gradio as gr
351
+
352
+ with gr.Blocks() as demo:
353
+ name = gr.Textbox(label="Name")
354
+ output = gr.Textbox(label="Output Box")
355
+ greet_btn = gr.Button("Greet")
356
+
357
+ @gr.on(triggers=[name.submit, greet_btn.click], inputs=name, outputs=output)
358
+ def greet(name):
359
+ return "Hello " + name + "!"
360
+
361
+ demo.launch()
362
+ ```
363
+
364
+ ## Render Merge
365
+
366
+ ```python
367
+ import gradio as gr
368
+ import time
369
+
370
+ with gr.Blocks() as demo:
371
+ text_count = gr.Slider(1, 5, value=1, step=1, label="Textbox Count")
372
+
373
+ @gr.render(inputs=text_count)
374
+ def render_count(count):
375
+ boxes = []
376
+ for i in range(count):
377
+ box = gr.Textbox(label=f"Box {i}")
378
+ boxes.append(box)
379
+
380
+ def merge(*args):
381
+ time.sleep(0.2) # simulate a delay
382
+ return " ".join(args)
383
+
384
+ merge_btn.click(merge, boxes, output)
385
+
386
+ def clear():
387
+ time.sleep(0.2) # simulate a delay
388
+ return [" "] * count
389
+
390
+ clear_btn.click(clear, None, boxes)
391
+
392
+ def countup():
393
+ time.sleep(0.2) # simulate a delay
394
+ return list(range(count))
395
+
396
+ count_btn.click(countup, None, boxes, queue=False)
397
+
398
+ with gr.Row():
399
+ merge_btn = gr.Button("Merge")
400
+ clear_btn = gr.Button("Clear")
401
+ count_btn = gr.Button("Count")
402
+
403
+ output = gr.Textbox()
404
+
405
+ demo.launch()
406
+ ```
407
+
408
+ ## Reverse Audio 2
409
+
410
+ ```python
411
+ import gradio as gr
412
+ import numpy as np
413
+
414
+ def reverse_audio(audio):
415
+ sr, data = audio
416
+ return (sr, np.flipud(data))
417
+
418
+ demo = gr.Interface(fn=reverse_audio,
419
+ inputs="microphone",
420
+ outputs="audio", api_name="predict")
421
+
422
+ demo.launch()
423
+ ```
424
+
425
+ ## Sepia Filter
426
+
427
+ ```python
428
+ import numpy as np
429
+ import gradio as gr
430
+
431
+ def sepia(input_img):
432
+ sepia_filter = np.array([
433
+ [0.393, 0.769, 0.189],
434
+ [0.349, 0.686, 0.168],
435
+ [0.272, 0.534, 0.131]
436
+ ])
437
+ sepia_img = input_img.dot(sepia_filter.T)
438
+ sepia_img /= sepia_img.max()
439
+ return sepia_img
440
+
441
+ demo = gr.Interface(sepia, gr.Image(), "image", api_name="predict")
442
+ demo.launch()
443
+ ```
444
+
445
+ ## Sort Records
446
+
447
+ ```python
448
+ import gradio as gr
449
+
450
+ def sort_records(records):
451
+ return records.sort("Quantity")
452
+
453
+ demo = gr.Interface(
454
+ sort_records,
455
+ gr.Dataframe(
456
+ headers=["Item", "Quantity"],
457
+ datatype=["str", "number"],
458
+ row_count=3,
459
+ column_count=2,
460
+ column_limits=(2, 2),
461
+ type="polars"
462
+ ),
463
+ "dataframe",
464
+ description="Sort by Quantity"
465
+ )
466
+
467
+ demo.launch()
468
+ ```
469
+
470
+ ## Streaming Simple
471
+
472
+ ```python
473
+ import gradio as gr
474
+
475
+ with gr.Blocks() as demo:
476
+ with gr.Row():
477
+ with gr.Column():
478
+ input_img = gr.Image(label="Input", sources="webcam")
479
+ with gr.Column():
480
+ output_img = gr.Image(label="Output")
481
+ input_img.stream(lambda s: s, input_img, output_img, time_limit=15, stream_every=0.1, concurrency_limit=30)
482
+
483
+ if __name__ == "__main__":
484
+
485
+ demo.launch()
486
+ ```
487
+
488
+ ## Tabbed Interface Lite
489
+
490
+ ```python
491
+ import gradio as gr
492
+
493
+ hello_world = gr.Interface(lambda name: "Hello " + name, "text", "text", api_name="predict")
494
+ bye_world = gr.Interface(lambda name: "Bye " + name, "text", "text", api_name="predict")
495
+ chat = gr.ChatInterface(lambda *args: "Hello " + args[0], api_name="chat")
496
+
497
+ demo = gr.TabbedInterface([hello_world, bye_world, chat], ["Hello World", "Bye World", "Chat"])
498
+
499
+ demo.launch()
500
+ ```
501
+
502
+ ## Tax Calculator
503
+
504
+ ```python
505
+ import gradio as gr
506
+
507
+ def tax_calculator(income, marital_status, assets):
508
+ tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)]
509
+ total_deductible = sum(cost for cost, deductible in zip(assets["Cost"], assets["Deductible"]) if deductible)
510
+ taxable_income = income - total_deductible
511
+
512
+ total_tax = 0
513
+ for bracket, rate in tax_brackets:
514
+ if taxable_income > bracket:
515
+ total_tax += (taxable_income - bracket) * rate / 100
516
+
517
+ if marital_status == "Married":
518
+ total_tax *= 0.75
519
+ elif marital_status == "Divorced":
520
+ total_tax *= 0.8
521
+
522
+ return round(total_tax)
523
+
524
+ demo = gr.Interface(
525
+ tax_calculator,
526
+ [
527
+ "number",
528
+ gr.Radio(["Single", "Married", "Divorced"]),
529
+ gr.Dataframe(
530
+ headers=["Item", "Cost", "Deductible"],
531
+ datatype=["str", "number", "bool"],
532
+ label="Assets Purchased this Year",
533
+ ),
534
+ ],
535
+ gr.Number(label="Tax due"),
536
+ examples=[
537
+ [10000, "Married", [["Suit", 5000, True], ["Laptop (for work)", 800, False], ["Car", 1800, True]]],
538
+ [80000, "Single", [["Suit", 800, True], ["Watch", 1800, True], ["Food", 800, True]]],
539
+ ],
540
+ live=True,
541
+ api_name="predict"
542
+ )
543
+
544
+ demo.launch()
545
+ ```
546
+
547
+ ## Timer Simple
548
+
549
+ ```python
550
+ import gradio as gr
551
+ import random
552
+ import time
553
+
554
+ with gr.Blocks() as demo:
555
+ timer = gr.Timer(1)
556
+ timestamp = gr.Number(label="Time")
557
+ timer.tick(lambda: round(time.time()), outputs=timestamp, api_name="timestamp")
558
+
559
+ number = gr.Number(lambda: random.randint(1, 10), every=timer, label="Random Number")
560
+ with gr.Row():
561
+ gr.Button("Start").click(lambda: gr.Timer(active=True), None, timer)
562
+ gr.Button("Stop").click(lambda: gr.Timer(active=False), None, timer)
563
+ gr.Button("Go Fast").click(lambda: 0.2, None, timer)
564
+
565
+ if __name__ == "__main__":
566
+ demo.launch()
567
+ ```
568
+
569
+ ## Variable Outputs
570
+
571
+ ```python
572
+ import gradio as gr
573
+
574
+ max_textboxes = 10
575
+
576
+ def variable_outputs(k):
577
+ k = int(k)
578
+ return [gr.Textbox(visible=True)]*k + [gr.Textbox(visible=False)]*(max_textboxes-k)
579
+
580
+ with gr.Blocks() as demo:
581
+ s = gr.Slider(1, max_textboxes, value=max_textboxes, step=1, label="How many textboxes to show:")
582
+ textboxes = []
583
+ for i in range(max_textboxes):
584
+ t = gr.Textbox(f"Textbox {i}")
585
+ textboxes.append(t)
586
+
587
+ s.change(variable_outputs, s, textboxes)
588
+
589
+ if __name__ == "__main__":
590
+ demo.launch()
591
+ ```
592
+
593
+ ## Video Identity
594
+
595
+ ```python
596
+ import gradio as gr
597
+ from gradio.media import get_video
598
+
599
+ def video_identity(video):
600
+ return video
601
+
602
+ # get_video() returns file paths to sample media included with Gradio
603
+ demo = gr.Interface(video_identity,
604
+ gr.Video(),
605
+ "playable_video",
606
+ examples=[
607
+ get_video("world.mp4")
608
+ ],
609
+ cache_examples=True,
610
+ api_name="predict",)
611
+
612
+ demo.launch()
613
+ ```