Chenglu-She commited on
Commit
b34864a
·
verified ·
1 Parent(s): 59a8d69

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +10 -820
  2. src/README.md +10 -820
  3. src/backend/gradio_log/log.py +1 -1
  4. src/pyproject.toml +1 -1
README.md CHANGED
@@ -1,8 +1,12 @@
1
-
2
  # `gradio_log`
3
  <a href="https://pypi.org/project/gradio_log/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_log"></a>
4
 
5
- A Log component for Gradio which can easily show some log file in the interface.
 
 
 
 
 
6
 
7
  ## Installation
8
 
@@ -13,830 +17,16 @@ pip install gradio_log
13
  ## Usage
14
 
15
  ```python
16
- import logging
17
- from pathlib import Path
18
-
19
  import gradio as gr
20
  from gradio_log import Log
21
 
22
-
23
- class CustomFormatter(logging.Formatter):
24
-
25
- green = "\x1b[32;20m"
26
- blue = "\x1b[34;20m"
27
- yellow = "\x1b[33;20m"
28
- red = "\x1b[31;20m"
29
- bold_red = "\x1b[31;1m"
30
- reset = "\x1b[0m"
31
- format = "%(asctime)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
32
-
33
- FORMATS = {
34
- logging.DEBUG: blue + format + reset,
35
- logging.INFO: green + format + reset,
36
- logging.WARNING: yellow + format + reset,
37
- logging.ERROR: red + format + reset,
38
- logging.CRITICAL: bold_red + format + reset,
39
- }
40
-
41
- def format(self, record):
42
- log_fmt = self.FORMATS.get(record.levelno)
43
- formatter = logging.Formatter(log_fmt)
44
- return formatter.format(record)
45
-
46
-
47
- formatter = CustomFormatter()
48
-
49
- log_file = "/tmp/gradio_log.txt"
50
- Path(log_file).touch()
51
-
52
- ch = logging.FileHandler(log_file)
53
- ch.setLevel(logging.DEBUG)
54
- ch.setFormatter(formatter)
55
-
56
- logger = logging.getLogger("gradio_log")
57
- logger.setLevel(logging.DEBUG)
58
- for handler in logger.handlers:
59
- logger.removeHandler(handler)
60
- logger.addHandler(ch)
61
-
62
-
63
- logger.info("The logs will be displayed in here.")
64
-
65
-
66
- def create_log_handler(level):
67
- def l(text):
68
- getattr(logger, level)(text)
69
-
70
- return l
71
-
72
 
73
  with gr.Blocks() as demo:
74
- text = gr.Textbox(label="Enter text to write to log file")
75
- with gr.Row():
76
- for l in ["debug", "info", "warning", "error", "critical"]:
77
- button = gr.Button(f"log as {l}")
78
- button.click(fn=create_log_handler(l), inputs=text)
79
- Log(log_file, dark=True)
80
-
81
 
82
  if __name__ == "__main__":
83
- demo.launch(ssr_mode=True)
84
-
85
- ```
86
-
87
- ## `Log`
88
-
89
- ### Initialization
90
-
91
- <table>
92
- <thead>
93
- <tr>
94
- <th align="left">name</th>
95
- <th align="left" style="width: 25%;">type</th>
96
- <th align="left">default</th>
97
- <th align="left">description</th>
98
- </tr>
99
- </thead>
100
- <tbody>
101
- <tr>
102
- <td align="left"><code>log_file</code></td>
103
- <td align="left" style="width: 25%;">
104
-
105
- ```python
106
- str
107
- ```
108
-
109
- </td>
110
- <td align="left"><code>None</code></td>
111
- <td align="left">the log file path to read from.</td>
112
- </tr>
113
-
114
- <tr>
115
- <td align="left"><code>tail</code></td>
116
- <td align="left" style="width: 25%;">
117
-
118
- ```python
119
- int
120
- ```
121
-
122
- </td>
123
- <td align="left"><code>100</code></td>
124
- <td align="left">from the end of the file, the number of lines to start read from.</td>
125
- </tr>
126
-
127
- <tr>
128
- <td align="left"><code>dark</code></td>
129
- <td align="left" style="width: 25%;">
130
-
131
- ```python
132
- bool
133
- ```
134
-
135
- </td>
136
- <td align="left"><code>False</code></td>
137
- <td align="left">if True, will render the component in dark mode.</td>
138
- </tr>
139
-
140
- <tr>
141
- <td align="left"><code>height</code></td>
142
- <td align="left" style="width: 25%;">
143
-
144
- ```python
145
- str | int | None
146
- ```
147
-
148
- </td>
149
- <td align="left"><code>240</code></td>
150
- <td align="left">None</td>
151
- </tr>
152
-
153
- <tr>
154
- <td align="left"><code>xterm_allow_proposed_api</code></td>
155
- <td align="left" style="width: 25%;">
156
-
157
- ```python
158
- typing.Optional[bool][bool, None]
159
- ```
160
-
161
- </td>
162
- <td align="left"><code>False</code></td>
163
- <td align="left">None</td>
164
- </tr>
165
-
166
- <tr>
167
- <td align="left"><code>xterm_allow_transparency</code></td>
168
- <td align="left" style="width: 25%;">
169
-
170
- ```python
171
- typing.Optional[bool][bool, None]
172
- ```
173
-
174
- </td>
175
- <td align="left"><code>False</code></td>
176
- <td align="left">None</td>
177
- </tr>
178
-
179
- <tr>
180
- <td align="left"><code>xterm_alt_click_moves_cursor</code></td>
181
- <td align="left" style="width: 25%;">
182
-
183
- ```python
184
- typing.Optional[bool][bool, None]
185
- ```
186
-
187
- </td>
188
- <td align="left"><code>True</code></td>
189
- <td align="left">None</td>
190
- </tr>
191
-
192
- <tr>
193
- <td align="left"><code>xterm_convert_eol</code></td>
194
- <td align="left" style="width: 25%;">
195
-
196
- ```python
197
- typing.Optional[bool][bool, None]
198
- ```
199
-
200
- </td>
201
- <td align="left"><code>False</code></td>
202
- <td align="left">None</td>
203
- </tr>
204
-
205
- <tr>
206
- <td align="left"><code>xterm_cursor_blink</code></td>
207
- <td align="left" style="width: 25%;">
208
-
209
- ```python
210
- typing.Optional[bool][bool, None]
211
- ```
212
-
213
- </td>
214
- <td align="left"><code>False</code></td>
215
- <td align="left">None</td>
216
- </tr>
217
-
218
- <tr>
219
- <td align="left"><code>xterm_cursor_inactive_style</code></td>
220
- <td align="left" style="width: 25%;">
221
-
222
- ```python
223
- "outline" | "block" | "bar" | "underline" | "none"
224
- ```
225
-
226
- </td>
227
- <td align="left"><code>"outline"</code></td>
228
- <td align="left">None</td>
229
- </tr>
230
-
231
- <tr>
232
- <td align="left"><code>xterm_cursor_style</code></td>
233
- <td align="left" style="width: 25%;">
234
-
235
- ```python
236
- "block" | "underline" | "bar"
237
- ```
238
-
239
- </td>
240
- <td align="left"><code>"block"</code></td>
241
- <td align="left">None</td>
242
- </tr>
243
-
244
- <tr>
245
- <td align="left"><code>xterm_cursor_width</code></td>
246
- <td align="left" style="width: 25%;">
247
-
248
- ```python
249
- typing.Optional[int][int, None]
250
- ```
251
-
252
- </td>
253
- <td align="left"><code>1</code></td>
254
- <td align="left">None</td>
255
- </tr>
256
-
257
- <tr>
258
- <td align="left"><code>xterm_custom_glyphs</code></td>
259
- <td align="left" style="width: 25%;">
260
-
261
- ```python
262
- typing.Optional[bool][bool, None]
263
- ```
264
-
265
- </td>
266
- <td align="left"><code>False</code></td>
267
- <td align="left">None</td>
268
- </tr>
269
-
270
- <tr>
271
- <td align="left"><code>xterm_disable_stdin</code></td>
272
- <td align="left" style="width: 25%;">
273
-
274
- ```python
275
- typing.Optional[bool][bool, None]
276
- ```
277
-
278
- </td>
279
- <td align="left"><code>True</code></td>
280
- <td align="left">None</td>
281
- </tr>
282
-
283
- <tr>
284
- <td align="left"><code>xterm_document_override</code></td>
285
- <td align="left" style="width: 25%;">
286
-
287
- ```python
288
- typing.Optional[typing.Any][typing.Any, None]
289
- ```
290
-
291
- </td>
292
- <td align="left"><code>None</code></td>
293
- <td align="left">None</td>
294
- </tr>
295
-
296
- <tr>
297
- <td align="left"><code>xterm_draw_bold_text_in_bright_colors</code></td>
298
- <td align="left" style="width: 25%;">
299
-
300
- ```python
301
- typing.Optional[bool][bool, None]
302
- ```
303
-
304
- </td>
305
- <td align="left"><code>True</code></td>
306
- <td align="left">None</td>
307
- </tr>
308
-
309
- <tr>
310
- <td align="left"><code>xterm_fast_scroll_modifier</code></td>
311
- <td align="left" style="width: 25%;">
312
-
313
- ```python
314
- typing.Optional[
315
- typing.Literal["none", "alt", "ctrl", "shift"]
316
- ]["none" | "alt" | "ctrl" | "shift", None]
317
- ```
318
-
319
- </td>
320
- <td align="left"><code>"alt"</code></td>
321
- <td align="left">None</td>
322
- </tr>
323
-
324
- <tr>
325
- <td align="left"><code>xterm_fast_scroll_sensitivity</code></td>
326
- <td align="left" style="width: 25%;">
327
-
328
- ```python
329
- typing.Optional[int][int, None]
330
- ```
331
-
332
- </td>
333
- <td align="left"><code>1</code></td>
334
- <td align="left">None</td>
335
- </tr>
336
-
337
- <tr>
338
- <td align="left"><code>xterm_font_family</code></td>
339
- <td align="left" style="width: 25%;">
340
-
341
- ```python
342
- typing.Optional[str][str, None]
343
- ```
344
-
345
- </td>
346
- <td align="left"><code>"courier-new, courier, monospace"</code></td>
347
- <td align="left">None</td>
348
- </tr>
349
-
350
- <tr>
351
- <td align="left"><code>xterm_font_size</code></td>
352
- <td align="left" style="width: 25%;">
353
-
354
- ```python
355
- typing.Optional[int][int, None]
356
- ```
357
-
358
- </td>
359
- <td align="left"><code>15</code></td>
360
- <td align="left">None</td>
361
- </tr>
362
-
363
- <tr>
364
- <td align="left"><code>xterm_font_weight</code></td>
365
- <td align="left" style="width: 25%;">
366
-
367
- ```python
368
- typing.Optional[
369
- typing.Literal[
370
- "normal",
371
- "bold",
372
- "100",
373
- "200",
374
- "300",
375
- "400",
376
- "500",
377
- "600",
378
- "700",
379
- "800",
380
- "900",
381
- ]
382
- ][
383
- "normal"
384
- | "bold"
385
- | "100"
386
- | "200"
387
- | "300"
388
- | "400"
389
- | "500"
390
- | "600"
391
- | "700"
392
- | "800"
393
- | "900",
394
- None,
395
- ]
396
- ```
397
-
398
- </td>
399
- <td align="left"><code>"normal"</code></td>
400
- <td align="left">None</td>
401
- </tr>
402
-
403
- <tr>
404
- <td align="left"><code>xterm_font_weight_bold</code></td>
405
- <td align="left" style="width: 25%;">
406
-
407
- ```python
408
- typing.Optional[
409
- typing.Literal[
410
- "normal",
411
- "bold",
412
- "100",
413
- "200",
414
- "300",
415
- "400",
416
- "500",
417
- "600",
418
- "700",
419
- "800",
420
- "900",
421
- ]
422
- ][
423
- "normal"
424
- | "bold"
425
- | "100"
426
- | "200"
427
- | "300"
428
- | "400"
429
- | "500"
430
- | "600"
431
- | "700"
432
- | "800"
433
- | "900",
434
- None,
435
- ]
436
- ```
437
-
438
- </td>
439
- <td align="left"><code>"bold"</code></td>
440
- <td align="left">None</td>
441
- </tr>
442
-
443
- <tr>
444
- <td align="left"><code>xterm_ignore_bracketed_paste_mode</code></td>
445
- <td align="left" style="width: 25%;">
446
-
447
- ```python
448
- typing.Optional[bool][bool, None]
449
- ```
450
-
451
- </td>
452
- <td align="left"><code>False</code></td>
453
- <td align="left">None</td>
454
- </tr>
455
-
456
- <tr>
457
- <td align="left"><code>xterm_letter_spacing</code></td>
458
- <td align="left" style="width: 25%;">
459
-
460
- ```python
461
- typing.Optional[float][float, None]
462
  ```
463
 
464
- </td>
465
- <td align="left"><code>0</code></td>
466
- <td align="left">None</td>
467
- </tr>
468
-
469
- <tr>
470
- <td align="left"><code>xterm_line_height</code></td>
471
- <td align="left" style="width: 25%;">
472
-
473
- ```python
474
- typing.Optional[float][float, None]
475
- ```
476
-
477
- </td>
478
- <td align="left"><code>1.0</code></td>
479
- <td align="left">None</td>
480
- </tr>
481
-
482
- <tr>
483
- <td align="left"><code>xterm_log_level</code></td>
484
- <td align="left" style="width: 25%;">
485
-
486
- ```python
487
- typing.Optional[
488
- typing.Literal[
489
- "trace", "debug", "info", "warn", "error", "off"
490
- ]
491
- ][
492
- "trace" | "debug" | "info" | "warn" | "error" | "off",
493
- None,
494
- ]
495
- ```
496
-
497
- </td>
498
- <td align="left"><code>"info"</code></td>
499
- <td align="left">None</td>
500
- </tr>
501
-
502
- <tr>
503
- <td align="left"><code>xterm_mac_option_click_forces_selection</code></td>
504
- <td align="left" style="width: 25%;">
505
-
506
- ```python
507
- typing.Optional[bool][bool, None]
508
- ```
509
-
510
- </td>
511
- <td align="left"><code>False</code></td>
512
- <td align="left">None</td>
513
- </tr>
514
-
515
- <tr>
516
- <td align="left"><code>xterm_mac_option_is_meta</code></td>
517
- <td align="left" style="width: 25%;">
518
-
519
- ```python
520
- typing.Optional[bool][bool, None]
521
- ```
522
-
523
- </td>
524
- <td align="left"><code>False</code></td>
525
- <td align="left">None</td>
526
- </tr>
527
-
528
- <tr>
529
- <td align="left"><code>xterm_minimum_contrast_ratio</code></td>
530
- <td align="left" style="width: 25%;">
531
-
532
- ```python
533
- typing.Optional[int][int, None]
534
- ```
535
-
536
- </td>
537
- <td align="left"><code>1</code></td>
538
- <td align="left">None</td>
539
- </tr>
540
-
541
- <tr>
542
- <td align="left"><code>xterm_overview_ruler_width</code></td>
543
- <td align="left" style="width: 25%;">
544
-
545
- ```python
546
- typing.Optional[int][int, None]
547
- ```
548
-
549
- </td>
550
- <td align="left"><code>0</code></td>
551
- <td align="left">None</td>
552
- </tr>
553
-
554
- <tr>
555
- <td align="left"><code>xterm_rescale_overlapping_glyphs</code></td>
556
- <td align="left" style="width: 25%;">
557
-
558
- ```python
559
- typing.Optional[bool][bool, None]
560
- ```
561
-
562
- </td>
563
- <td align="left"><code>False</code></td>
564
- <td align="left">None</td>
565
- </tr>
566
-
567
- <tr>
568
- <td align="left"><code>xterm_screen_reader_mode</code></td>
569
- <td align="left" style="width: 25%;">
570
-
571
- ```python
572
- typing.Optional[bool][bool, None]
573
- ```
574
-
575
- </td>
576
- <td align="left"><code>False</code></td>
577
- <td align="left">None</td>
578
- </tr>
579
-
580
- <tr>
581
- <td align="left"><code>xterm_scroll_on_user_input</code></td>
582
- <td align="left" style="width: 25%;">
583
-
584
- ```python
585
- typing.Optional[bool][bool, None]
586
- ```
587
-
588
- </td>
589
- <td align="left"><code>True</code></td>
590
- <td align="left">None</td>
591
- </tr>
592
-
593
- <tr>
594
- <td align="left"><code>xterm_scroll_sensitivity</code></td>
595
- <td align="left" style="width: 25%;">
596
-
597
- ```python
598
- typing.Optional[int][int, None]
599
- ```
600
-
601
- </td>
602
- <td align="left"><code>1</code></td>
603
- <td align="left">None</td>
604
- </tr>
605
-
606
- <tr>
607
- <td align="left"><code>xterm_scrollback</code></td>
608
- <td align="left" style="width: 25%;">
609
-
610
- ```python
611
- typing.Optional[int][int, None]
612
- ```
613
-
614
- </td>
615
- <td align="left"><code>1000</code></td>
616
- <td align="left">None</td>
617
- </tr>
618
-
619
- <tr>
620
- <td align="left"><code>xterm_smooth_scroll_duration</code></td>
621
- <td align="left" style="width: 25%;">
622
-
623
- ```python
624
- typing.Optional[int][int, None]
625
- ```
626
-
627
- </td>
628
- <td align="left"><code>0</code></td>
629
- <td align="left">None</td>
630
- </tr>
631
-
632
- <tr>
633
- <td align="left"><code>xterm_tab_stop_width</code></td>
634
- <td align="left" style="width: 25%;">
635
-
636
- ```python
637
- typing.Optional[int][int, None]
638
- ```
639
-
640
- </td>
641
- <td align="left"><code>8</code></td>
642
- <td align="left">None</td>
643
- </tr>
644
-
645
- <tr>
646
- <td align="left"><code>xterm_windows_mode</code></td>
647
- <td align="left" style="width: 25%;">
648
-
649
- ```python
650
- typing.Optional[bool][bool, None]
651
- ```
652
-
653
- </td>
654
- <td align="left"><code>False</code></td>
655
- <td align="left">None</td>
656
- </tr>
657
-
658
- <tr>
659
- <td align="left"><code>label</code></td>
660
- <td align="left" style="width: 25%;">
661
-
662
- ```python
663
- str | None
664
- ```
665
-
666
- </td>
667
- <td align="left"><code>None</code></td>
668
- <td align="left">The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.</td>
669
- </tr>
670
-
671
- <tr>
672
- <td align="left"><code>info</code></td>
673
- <td align="left" style="width: 25%;">
674
-
675
- ```python
676
- str | None
677
- ```
678
-
679
- </td>
680
- <td align="left"><code>None</code></td>
681
- <td align="left">additional component description.</td>
682
- </tr>
683
-
684
- <tr>
685
- <td align="left"><code>every</code></td>
686
- <td align="left" style="width: 25%;">
687
-
688
- ```python
689
- float
690
- ```
691
-
692
- </td>
693
- <td align="left"><code>0.5</code></td>
694
- <td align="left">New log pulling interval.</td>
695
- </tr>
696
-
697
- <tr>
698
- <td align="left"><code>show_label</code></td>
699
- <td align="left" style="width: 25%;">
700
-
701
- ```python
702
- bool | None
703
- ```
704
-
705
- </td>
706
- <td align="left"><code>None</code></td>
707
- <td align="left">if True, will display label.</td>
708
- </tr>
709
-
710
- <tr>
711
- <td align="left"><code>container</code></td>
712
- <td align="left" style="width: 25%;">
713
-
714
- ```python
715
- bool
716
- ```
717
-
718
- </td>
719
- <td align="left"><code>True</code></td>
720
- <td align="left">If True, will place the component in a container - providing some extra padding around the border.</td>
721
- </tr>
722
-
723
- <tr>
724
- <td align="left"><code>scale</code></td>
725
- <td align="left" style="width: 25%;">
726
-
727
- ```python
728
- int | None
729
- ```
730
-
731
- </td>
732
- <td align="left"><code>None</code></td>
733
- <td align="left">relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.</td>
734
- </tr>
735
-
736
- <tr>
737
- <td align="left"><code>min_width</code></td>
738
- <td align="left" style="width: 25%;">
739
-
740
- ```python
741
- int
742
- ```
743
-
744
- </td>
745
- <td align="left"><code>160</code></td>
746
- <td align="left">minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.</td>
747
- </tr>
748
-
749
- <tr>
750
- <td align="left"><code>interactive</code></td>
751
- <td align="left" style="width: 25%;">
752
-
753
- ```python
754
- bool | None
755
- ```
756
-
757
- </td>
758
- <td align="left"><code>None</code></td>
759
- <td align="left">if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.</td>
760
- </tr>
761
-
762
- <tr>
763
- <td align="left"><code>visible</code></td>
764
- <td align="left" style="width: 25%;">
765
-
766
- ```python
767
- bool
768
- ```
769
-
770
- </td>
771
- <td align="left"><code>True</code></td>
772
- <td align="left">If False, component will be hidden.</td>
773
- </tr>
774
-
775
- <tr>
776
- <td align="left"><code>elem_id</code></td>
777
- <td align="left" style="width: 25%;">
778
-
779
- ```python
780
- str | None
781
- ```
782
-
783
- </td>
784
- <td align="left"><code>None</code></td>
785
- <td align="left">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
786
- </tr>
787
-
788
- <tr>
789
- <td align="left"><code>elem_classes</code></td>
790
- <td align="left" style="width: 25%;">
791
-
792
- ```python
793
- list[str] | str | None
794
- ```
795
-
796
- </td>
797
- <td align="left"><code>None</code></td>
798
- <td align="left">An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
799
- </tr>
800
-
801
- <tr>
802
- <td align="left"><code>render</code></td>
803
- <td align="left" style="width: 25%;">
804
-
805
- ```python
806
- bool
807
- ```
808
-
809
- </td>
810
- <td align="left"><code>True</code></td>
811
- <td align="left">If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
812
- </tr>
813
- </tbody></table>
814
-
815
-
816
- ### Events
817
-
818
- | name | description |
819
- |:-----|:------------|
820
- | `load` | This listener is triggered when the Log initially loads in the browser. |
821
-
822
-
823
-
824
- ### User function
825
-
826
- The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
827
-
828
- - When used as an Input, the component only impacts the input signature of the user function.
829
- - When used as an output, the component only impacts the return signature of the user function.
830
-
831
- The code snippet below is accurate in cases where the component is used as both an input and an output.
832
-
833
- - **As output:** Is passed, the preprocessed input data sent to the user's function in the backend.
834
-
835
-
836
- ```python
837
- def predict(
838
- value: typing.Any
839
- ) -> Unknown:
840
- return value
841
- ```
842
-
 
 
1
  # `gradio_log`
2
  <a href="https://pypi.org/project/gradio_log/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_log"></a>
3
 
4
+ A Log component of Gradio which can easily continuously print any log file content into the user interface.
5
+
6
+ > Credit: [Featurize 算力平台](https://featurize.cn)
7
+
8
+ ![static](./assets/static.png)
9
+ ![dynamic](./assets/dynamic.gif)
10
 
11
  ## Installation
12
 
 
17
  ## Usage
18
 
19
  ```python
 
 
 
20
  import gradio as gr
21
  from gradio_log import Log
22
 
23
+ log_file = "/path/to/your/log_file.txt"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  with gr.Blocks() as demo:
26
+ Log(log_file, dark=True, xterm_font_size=12)
 
 
 
 
 
 
27
 
28
  if __name__ == "__main__":
29
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ```
31
 
32
+ After launched, try to add some new logs into the log file, and you will see the new logs are printed in the user interface.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/README.md CHANGED
@@ -1,8 +1,12 @@
1
-
2
  # `gradio_log`
3
  <a href="https://pypi.org/project/gradio_log/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_log"></a>
4
 
5
- A Log component for Gradio which can easily show some log file in the interface.
 
 
 
 
 
6
 
7
  ## Installation
8
 
@@ -13,830 +17,16 @@ pip install gradio_log
13
  ## Usage
14
 
15
  ```python
16
- import logging
17
- from pathlib import Path
18
-
19
  import gradio as gr
20
  from gradio_log import Log
21
 
22
-
23
- class CustomFormatter(logging.Formatter):
24
-
25
- green = "\x1b[32;20m"
26
- blue = "\x1b[34;20m"
27
- yellow = "\x1b[33;20m"
28
- red = "\x1b[31;20m"
29
- bold_red = "\x1b[31;1m"
30
- reset = "\x1b[0m"
31
- format = "%(asctime)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
32
-
33
- FORMATS = {
34
- logging.DEBUG: blue + format + reset,
35
- logging.INFO: green + format + reset,
36
- logging.WARNING: yellow + format + reset,
37
- logging.ERROR: red + format + reset,
38
- logging.CRITICAL: bold_red + format + reset,
39
- }
40
-
41
- def format(self, record):
42
- log_fmt = self.FORMATS.get(record.levelno)
43
- formatter = logging.Formatter(log_fmt)
44
- return formatter.format(record)
45
-
46
-
47
- formatter = CustomFormatter()
48
-
49
- log_file = "/tmp/gradio_log.txt"
50
- Path(log_file).touch()
51
-
52
- ch = logging.FileHandler(log_file)
53
- ch.setLevel(logging.DEBUG)
54
- ch.setFormatter(formatter)
55
-
56
- logger = logging.getLogger("gradio_log")
57
- logger.setLevel(logging.DEBUG)
58
- for handler in logger.handlers:
59
- logger.removeHandler(handler)
60
- logger.addHandler(ch)
61
-
62
-
63
- logger.info("The logs will be displayed in here.")
64
-
65
-
66
- def create_log_handler(level):
67
- def l(text):
68
- getattr(logger, level)(text)
69
-
70
- return l
71
-
72
 
73
  with gr.Blocks() as demo:
74
- text = gr.Textbox(label="Enter text to write to log file")
75
- with gr.Row():
76
- for l in ["debug", "info", "warning", "error", "critical"]:
77
- button = gr.Button(f"log as {l}")
78
- button.click(fn=create_log_handler(l), inputs=text)
79
- Log(log_file, dark=True)
80
-
81
 
82
  if __name__ == "__main__":
83
- demo.launch(ssr_mode=True)
84
-
85
- ```
86
-
87
- ## `Log`
88
-
89
- ### Initialization
90
-
91
- <table>
92
- <thead>
93
- <tr>
94
- <th align="left">name</th>
95
- <th align="left" style="width: 25%;">type</th>
96
- <th align="left">default</th>
97
- <th align="left">description</th>
98
- </tr>
99
- </thead>
100
- <tbody>
101
- <tr>
102
- <td align="left"><code>log_file</code></td>
103
- <td align="left" style="width: 25%;">
104
-
105
- ```python
106
- str
107
- ```
108
-
109
- </td>
110
- <td align="left"><code>None</code></td>
111
- <td align="left">the log file path to read from.</td>
112
- </tr>
113
-
114
- <tr>
115
- <td align="left"><code>tail</code></td>
116
- <td align="left" style="width: 25%;">
117
-
118
- ```python
119
- int
120
- ```
121
-
122
- </td>
123
- <td align="left"><code>100</code></td>
124
- <td align="left">from the end of the file, the number of lines to start read from.</td>
125
- </tr>
126
-
127
- <tr>
128
- <td align="left"><code>dark</code></td>
129
- <td align="left" style="width: 25%;">
130
-
131
- ```python
132
- bool
133
- ```
134
-
135
- </td>
136
- <td align="left"><code>False</code></td>
137
- <td align="left">if True, will render the component in dark mode.</td>
138
- </tr>
139
-
140
- <tr>
141
- <td align="left"><code>height</code></td>
142
- <td align="left" style="width: 25%;">
143
-
144
- ```python
145
- str | int | None
146
- ```
147
-
148
- </td>
149
- <td align="left"><code>240</code></td>
150
- <td align="left">None</td>
151
- </tr>
152
-
153
- <tr>
154
- <td align="left"><code>xterm_allow_proposed_api</code></td>
155
- <td align="left" style="width: 25%;">
156
-
157
- ```python
158
- typing.Optional[bool][bool, None]
159
- ```
160
-
161
- </td>
162
- <td align="left"><code>False</code></td>
163
- <td align="left">None</td>
164
- </tr>
165
-
166
- <tr>
167
- <td align="left"><code>xterm_allow_transparency</code></td>
168
- <td align="left" style="width: 25%;">
169
-
170
- ```python
171
- typing.Optional[bool][bool, None]
172
- ```
173
-
174
- </td>
175
- <td align="left"><code>False</code></td>
176
- <td align="left">None</td>
177
- </tr>
178
-
179
- <tr>
180
- <td align="left"><code>xterm_alt_click_moves_cursor</code></td>
181
- <td align="left" style="width: 25%;">
182
-
183
- ```python
184
- typing.Optional[bool][bool, None]
185
- ```
186
-
187
- </td>
188
- <td align="left"><code>True</code></td>
189
- <td align="left">None</td>
190
- </tr>
191
-
192
- <tr>
193
- <td align="left"><code>xterm_convert_eol</code></td>
194
- <td align="left" style="width: 25%;">
195
-
196
- ```python
197
- typing.Optional[bool][bool, None]
198
- ```
199
-
200
- </td>
201
- <td align="left"><code>False</code></td>
202
- <td align="left">None</td>
203
- </tr>
204
-
205
- <tr>
206
- <td align="left"><code>xterm_cursor_blink</code></td>
207
- <td align="left" style="width: 25%;">
208
-
209
- ```python
210
- typing.Optional[bool][bool, None]
211
- ```
212
-
213
- </td>
214
- <td align="left"><code>False</code></td>
215
- <td align="left">None</td>
216
- </tr>
217
-
218
- <tr>
219
- <td align="left"><code>xterm_cursor_inactive_style</code></td>
220
- <td align="left" style="width: 25%;">
221
-
222
- ```python
223
- "outline" | "block" | "bar" | "underline" | "none"
224
- ```
225
-
226
- </td>
227
- <td align="left"><code>"outline"</code></td>
228
- <td align="left">None</td>
229
- </tr>
230
-
231
- <tr>
232
- <td align="left"><code>xterm_cursor_style</code></td>
233
- <td align="left" style="width: 25%;">
234
-
235
- ```python
236
- "block" | "underline" | "bar"
237
- ```
238
-
239
- </td>
240
- <td align="left"><code>"block"</code></td>
241
- <td align="left">None</td>
242
- </tr>
243
-
244
- <tr>
245
- <td align="left"><code>xterm_cursor_width</code></td>
246
- <td align="left" style="width: 25%;">
247
-
248
- ```python
249
- typing.Optional[int][int, None]
250
- ```
251
-
252
- </td>
253
- <td align="left"><code>1</code></td>
254
- <td align="left">None</td>
255
- </tr>
256
-
257
- <tr>
258
- <td align="left"><code>xterm_custom_glyphs</code></td>
259
- <td align="left" style="width: 25%;">
260
-
261
- ```python
262
- typing.Optional[bool][bool, None]
263
- ```
264
-
265
- </td>
266
- <td align="left"><code>False</code></td>
267
- <td align="left">None</td>
268
- </tr>
269
-
270
- <tr>
271
- <td align="left"><code>xterm_disable_stdin</code></td>
272
- <td align="left" style="width: 25%;">
273
-
274
- ```python
275
- typing.Optional[bool][bool, None]
276
- ```
277
-
278
- </td>
279
- <td align="left"><code>True</code></td>
280
- <td align="left">None</td>
281
- </tr>
282
-
283
- <tr>
284
- <td align="left"><code>xterm_document_override</code></td>
285
- <td align="left" style="width: 25%;">
286
-
287
- ```python
288
- typing.Optional[typing.Any][typing.Any, None]
289
- ```
290
-
291
- </td>
292
- <td align="left"><code>None</code></td>
293
- <td align="left">None</td>
294
- </tr>
295
-
296
- <tr>
297
- <td align="left"><code>xterm_draw_bold_text_in_bright_colors</code></td>
298
- <td align="left" style="width: 25%;">
299
-
300
- ```python
301
- typing.Optional[bool][bool, None]
302
- ```
303
-
304
- </td>
305
- <td align="left"><code>True</code></td>
306
- <td align="left">None</td>
307
- </tr>
308
-
309
- <tr>
310
- <td align="left"><code>xterm_fast_scroll_modifier</code></td>
311
- <td align="left" style="width: 25%;">
312
-
313
- ```python
314
- typing.Optional[
315
- typing.Literal["none", "alt", "ctrl", "shift"]
316
- ]["none" | "alt" | "ctrl" | "shift", None]
317
- ```
318
-
319
- </td>
320
- <td align="left"><code>"alt"</code></td>
321
- <td align="left">None</td>
322
- </tr>
323
-
324
- <tr>
325
- <td align="left"><code>xterm_fast_scroll_sensitivity</code></td>
326
- <td align="left" style="width: 25%;">
327
-
328
- ```python
329
- typing.Optional[int][int, None]
330
- ```
331
-
332
- </td>
333
- <td align="left"><code>1</code></td>
334
- <td align="left">None</td>
335
- </tr>
336
-
337
- <tr>
338
- <td align="left"><code>xterm_font_family</code></td>
339
- <td align="left" style="width: 25%;">
340
-
341
- ```python
342
- typing.Optional[str][str, None]
343
- ```
344
-
345
- </td>
346
- <td align="left"><code>"courier-new, courier, monospace"</code></td>
347
- <td align="left">None</td>
348
- </tr>
349
-
350
- <tr>
351
- <td align="left"><code>xterm_font_size</code></td>
352
- <td align="left" style="width: 25%;">
353
-
354
- ```python
355
- typing.Optional[int][int, None]
356
- ```
357
-
358
- </td>
359
- <td align="left"><code>15</code></td>
360
- <td align="left">None</td>
361
- </tr>
362
-
363
- <tr>
364
- <td align="left"><code>xterm_font_weight</code></td>
365
- <td align="left" style="width: 25%;">
366
-
367
- ```python
368
- typing.Optional[
369
- typing.Literal[
370
- "normal",
371
- "bold",
372
- "100",
373
- "200",
374
- "300",
375
- "400",
376
- "500",
377
- "600",
378
- "700",
379
- "800",
380
- "900",
381
- ]
382
- ][
383
- "normal"
384
- | "bold"
385
- | "100"
386
- | "200"
387
- | "300"
388
- | "400"
389
- | "500"
390
- | "600"
391
- | "700"
392
- | "800"
393
- | "900",
394
- None,
395
- ]
396
- ```
397
-
398
- </td>
399
- <td align="left"><code>"normal"</code></td>
400
- <td align="left">None</td>
401
- </tr>
402
-
403
- <tr>
404
- <td align="left"><code>xterm_font_weight_bold</code></td>
405
- <td align="left" style="width: 25%;">
406
-
407
- ```python
408
- typing.Optional[
409
- typing.Literal[
410
- "normal",
411
- "bold",
412
- "100",
413
- "200",
414
- "300",
415
- "400",
416
- "500",
417
- "600",
418
- "700",
419
- "800",
420
- "900",
421
- ]
422
- ][
423
- "normal"
424
- | "bold"
425
- | "100"
426
- | "200"
427
- | "300"
428
- | "400"
429
- | "500"
430
- | "600"
431
- | "700"
432
- | "800"
433
- | "900",
434
- None,
435
- ]
436
- ```
437
-
438
- </td>
439
- <td align="left"><code>"bold"</code></td>
440
- <td align="left">None</td>
441
- </tr>
442
-
443
- <tr>
444
- <td align="left"><code>xterm_ignore_bracketed_paste_mode</code></td>
445
- <td align="left" style="width: 25%;">
446
-
447
- ```python
448
- typing.Optional[bool][bool, None]
449
- ```
450
-
451
- </td>
452
- <td align="left"><code>False</code></td>
453
- <td align="left">None</td>
454
- </tr>
455
-
456
- <tr>
457
- <td align="left"><code>xterm_letter_spacing</code></td>
458
- <td align="left" style="width: 25%;">
459
-
460
- ```python
461
- typing.Optional[float][float, None]
462
  ```
463
 
464
- </td>
465
- <td align="left"><code>0</code></td>
466
- <td align="left">None</td>
467
- </tr>
468
-
469
- <tr>
470
- <td align="left"><code>xterm_line_height</code></td>
471
- <td align="left" style="width: 25%;">
472
-
473
- ```python
474
- typing.Optional[float][float, None]
475
- ```
476
-
477
- </td>
478
- <td align="left"><code>1.0</code></td>
479
- <td align="left">None</td>
480
- </tr>
481
-
482
- <tr>
483
- <td align="left"><code>xterm_log_level</code></td>
484
- <td align="left" style="width: 25%;">
485
-
486
- ```python
487
- typing.Optional[
488
- typing.Literal[
489
- "trace", "debug", "info", "warn", "error", "off"
490
- ]
491
- ][
492
- "trace" | "debug" | "info" | "warn" | "error" | "off",
493
- None,
494
- ]
495
- ```
496
-
497
- </td>
498
- <td align="left"><code>"info"</code></td>
499
- <td align="left">None</td>
500
- </tr>
501
-
502
- <tr>
503
- <td align="left"><code>xterm_mac_option_click_forces_selection</code></td>
504
- <td align="left" style="width: 25%;">
505
-
506
- ```python
507
- typing.Optional[bool][bool, None]
508
- ```
509
-
510
- </td>
511
- <td align="left"><code>False</code></td>
512
- <td align="left">None</td>
513
- </tr>
514
-
515
- <tr>
516
- <td align="left"><code>xterm_mac_option_is_meta</code></td>
517
- <td align="left" style="width: 25%;">
518
-
519
- ```python
520
- typing.Optional[bool][bool, None]
521
- ```
522
-
523
- </td>
524
- <td align="left"><code>False</code></td>
525
- <td align="left">None</td>
526
- </tr>
527
-
528
- <tr>
529
- <td align="left"><code>xterm_minimum_contrast_ratio</code></td>
530
- <td align="left" style="width: 25%;">
531
-
532
- ```python
533
- typing.Optional[int][int, None]
534
- ```
535
-
536
- </td>
537
- <td align="left"><code>1</code></td>
538
- <td align="left">None</td>
539
- </tr>
540
-
541
- <tr>
542
- <td align="left"><code>xterm_overview_ruler_width</code></td>
543
- <td align="left" style="width: 25%;">
544
-
545
- ```python
546
- typing.Optional[int][int, None]
547
- ```
548
-
549
- </td>
550
- <td align="left"><code>0</code></td>
551
- <td align="left">None</td>
552
- </tr>
553
-
554
- <tr>
555
- <td align="left"><code>xterm_rescale_overlapping_glyphs</code></td>
556
- <td align="left" style="width: 25%;">
557
-
558
- ```python
559
- typing.Optional[bool][bool, None]
560
- ```
561
-
562
- </td>
563
- <td align="left"><code>False</code></td>
564
- <td align="left">None</td>
565
- </tr>
566
-
567
- <tr>
568
- <td align="left"><code>xterm_screen_reader_mode</code></td>
569
- <td align="left" style="width: 25%;">
570
-
571
- ```python
572
- typing.Optional[bool][bool, None]
573
- ```
574
-
575
- </td>
576
- <td align="left"><code>False</code></td>
577
- <td align="left">None</td>
578
- </tr>
579
-
580
- <tr>
581
- <td align="left"><code>xterm_scroll_on_user_input</code></td>
582
- <td align="left" style="width: 25%;">
583
-
584
- ```python
585
- typing.Optional[bool][bool, None]
586
- ```
587
-
588
- </td>
589
- <td align="left"><code>True</code></td>
590
- <td align="left">None</td>
591
- </tr>
592
-
593
- <tr>
594
- <td align="left"><code>xterm_scroll_sensitivity</code></td>
595
- <td align="left" style="width: 25%;">
596
-
597
- ```python
598
- typing.Optional[int][int, None]
599
- ```
600
-
601
- </td>
602
- <td align="left"><code>1</code></td>
603
- <td align="left">None</td>
604
- </tr>
605
-
606
- <tr>
607
- <td align="left"><code>xterm_scrollback</code></td>
608
- <td align="left" style="width: 25%;">
609
-
610
- ```python
611
- typing.Optional[int][int, None]
612
- ```
613
-
614
- </td>
615
- <td align="left"><code>1000</code></td>
616
- <td align="left">None</td>
617
- </tr>
618
-
619
- <tr>
620
- <td align="left"><code>xterm_smooth_scroll_duration</code></td>
621
- <td align="left" style="width: 25%;">
622
-
623
- ```python
624
- typing.Optional[int][int, None]
625
- ```
626
-
627
- </td>
628
- <td align="left"><code>0</code></td>
629
- <td align="left">None</td>
630
- </tr>
631
-
632
- <tr>
633
- <td align="left"><code>xterm_tab_stop_width</code></td>
634
- <td align="left" style="width: 25%;">
635
-
636
- ```python
637
- typing.Optional[int][int, None]
638
- ```
639
-
640
- </td>
641
- <td align="left"><code>8</code></td>
642
- <td align="left">None</td>
643
- </tr>
644
-
645
- <tr>
646
- <td align="left"><code>xterm_windows_mode</code></td>
647
- <td align="left" style="width: 25%;">
648
-
649
- ```python
650
- typing.Optional[bool][bool, None]
651
- ```
652
-
653
- </td>
654
- <td align="left"><code>False</code></td>
655
- <td align="left">None</td>
656
- </tr>
657
-
658
- <tr>
659
- <td align="left"><code>label</code></td>
660
- <td align="left" style="width: 25%;">
661
-
662
- ```python
663
- str | None
664
- ```
665
-
666
- </td>
667
- <td align="left"><code>None</code></td>
668
- <td align="left">The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.</td>
669
- </tr>
670
-
671
- <tr>
672
- <td align="left"><code>info</code></td>
673
- <td align="left" style="width: 25%;">
674
-
675
- ```python
676
- str | None
677
- ```
678
-
679
- </td>
680
- <td align="left"><code>None</code></td>
681
- <td align="left">additional component description.</td>
682
- </tr>
683
-
684
- <tr>
685
- <td align="left"><code>every</code></td>
686
- <td align="left" style="width: 25%;">
687
-
688
- ```python
689
- float
690
- ```
691
-
692
- </td>
693
- <td align="left"><code>0.5</code></td>
694
- <td align="left">New log pulling interval.</td>
695
- </tr>
696
-
697
- <tr>
698
- <td align="left"><code>show_label</code></td>
699
- <td align="left" style="width: 25%;">
700
-
701
- ```python
702
- bool | None
703
- ```
704
-
705
- </td>
706
- <td align="left"><code>None</code></td>
707
- <td align="left">if True, will display label.</td>
708
- </tr>
709
-
710
- <tr>
711
- <td align="left"><code>container</code></td>
712
- <td align="left" style="width: 25%;">
713
-
714
- ```python
715
- bool
716
- ```
717
-
718
- </td>
719
- <td align="left"><code>True</code></td>
720
- <td align="left">If True, will place the component in a container - providing some extra padding around the border.</td>
721
- </tr>
722
-
723
- <tr>
724
- <td align="left"><code>scale</code></td>
725
- <td align="left" style="width: 25%;">
726
-
727
- ```python
728
- int | None
729
- ```
730
-
731
- </td>
732
- <td align="left"><code>None</code></td>
733
- <td align="left">relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.</td>
734
- </tr>
735
-
736
- <tr>
737
- <td align="left"><code>min_width</code></td>
738
- <td align="left" style="width: 25%;">
739
-
740
- ```python
741
- int
742
- ```
743
-
744
- </td>
745
- <td align="left"><code>160</code></td>
746
- <td align="left">minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.</td>
747
- </tr>
748
-
749
- <tr>
750
- <td align="left"><code>interactive</code></td>
751
- <td align="left" style="width: 25%;">
752
-
753
- ```python
754
- bool | None
755
- ```
756
-
757
- </td>
758
- <td align="left"><code>None</code></td>
759
- <td align="left">if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.</td>
760
- </tr>
761
-
762
- <tr>
763
- <td align="left"><code>visible</code></td>
764
- <td align="left" style="width: 25%;">
765
-
766
- ```python
767
- bool
768
- ```
769
-
770
- </td>
771
- <td align="left"><code>True</code></td>
772
- <td align="left">If False, component will be hidden.</td>
773
- </tr>
774
-
775
- <tr>
776
- <td align="left"><code>elem_id</code></td>
777
- <td align="left" style="width: 25%;">
778
-
779
- ```python
780
- str | None
781
- ```
782
-
783
- </td>
784
- <td align="left"><code>None</code></td>
785
- <td align="left">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
786
- </tr>
787
-
788
- <tr>
789
- <td align="left"><code>elem_classes</code></td>
790
- <td align="left" style="width: 25%;">
791
-
792
- ```python
793
- list[str] | str | None
794
- ```
795
-
796
- </td>
797
- <td align="left"><code>None</code></td>
798
- <td align="left">An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
799
- </tr>
800
-
801
- <tr>
802
- <td align="left"><code>render</code></td>
803
- <td align="left" style="width: 25%;">
804
-
805
- ```python
806
- bool
807
- ```
808
-
809
- </td>
810
- <td align="left"><code>True</code></td>
811
- <td align="left">If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
812
- </tr>
813
- </tbody></table>
814
-
815
-
816
- ### Events
817
-
818
- | name | description |
819
- |:-----|:------------|
820
- | `load` | This listener is triggered when the Log initially loads in the browser. |
821
-
822
-
823
-
824
- ### User function
825
-
826
- The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
827
-
828
- - When used as an Input, the component only impacts the input signature of the user function.
829
- - When used as an output, the component only impacts the return signature of the user function.
830
-
831
- The code snippet below is accurate in cases where the component is used as both an input and an output.
832
-
833
- - **As output:** Is passed, the preprocessed input data sent to the user's function in the backend.
834
-
835
-
836
- ```python
837
- def predict(
838
- value: typing.Any
839
- ) -> Unknown:
840
- return value
841
- ```
842
-
 
 
1
  # `gradio_log`
2
  <a href="https://pypi.org/project/gradio_log/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_log"></a>
3
 
4
+ A Log component of Gradio which can easily continuously print any log file content into the user interface.
5
+
6
+ > Credit: [Featurize 算力平台](https://featurize.cn)
7
+
8
+ ![static](./assets/static.png)
9
+ ![dynamic](./assets/dynamic.gif)
10
 
11
  ## Installation
12
 
 
17
  ## Usage
18
 
19
  ```python
 
 
 
20
  import gradio as gr
21
  from gradio_log import Log
22
 
23
+ log_file = "/path/to/your/log_file.txt"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  with gr.Blocks() as demo:
26
+ Log(log_file, dark=True, xterm_font_size=12)
 
 
 
 
 
 
27
 
28
  if __name__ == "__main__":
29
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ```
31
 
32
+ After launched, try to add some new logs into the log file, and you will see the new logs are printed in the user interface.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/backend/gradio_log/log.py CHANGED
@@ -2,7 +2,6 @@
2
 
3
  from __future__ import annotations
4
 
5
- import time
6
  from typing import Any, Literal, Optional
7
 
8
  import gradio as gr
@@ -70,6 +69,7 @@ class Log(FormComponent):
70
  f.seek(current_pos)
71
  b = f.read().decode()
72
  current_pos = f.tell()
 
73
  return b
74
 
75
  def __init__(
 
2
 
3
  from __future__ import annotations
4
 
 
5
  from typing import Any, Literal, Optional
6
 
7
  import gradio as gr
 
69
  f.seek(current_pos)
70
  b = f.read().decode()
71
  current_pos = f.tell()
72
+ self.current_reading_positions[session_hash] = current_pos
73
  return b
74
 
75
  def __init__(
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "gradio_log"
11
- version = "0.0.7"
12
  description = "A Log component for Gradio which can easily show some log file in the interface."
13
  readme = "README.md"
14
  license = "Apache-2.0"
 
8
 
9
  [project]
10
  name = "gradio_log"
11
+ version = "0.0.8"
12
  description = "A Log component for Gradio which can easily show some log file in the interface."
13
  readme = "README.md"
14
  license = "Apache-2.0"