File size: 1,876 Bytes
6350667
 
83b02d0
 
 
0c163b8
6350667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03c7ea3
 
 
 
 
 
 
 
 
 
6350667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03c7ea3
 
 
 
 
 
 
 
 
 
6350667
 
 
 
 
 
 
 
 
83b02d0
 
0c163b8
 
 
 
 
 
83b02d0
 
 
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
from __future__ import annotations

from contextlib import contextmanager
import gradio as gr

# Shared CSS used by all "cells" in the notebook-style demo.
CELL_CSS = """
.cell-wrapper {
    border: 1px solid rgba(0, 0, 0, 0.9);
    border-radius: 14px;
    padding: 10px;
    margin-bottom: 10px;
    background: transparent;
}
.cell-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0 0 10px;
}
.health-box {
    border-radius: 14px;
    padding: 18px;
    border: 1px solid transparent;
}
.health-success {
    background: #dcfce7;
    border-color: #86efac;
    color: #14532d;
}
.health-fail {
    background: #fee2e2;
    border-color: #fecaca;
    color: #7f1d1d;
}
.health-box ul {
    margin: 12px 0 0;
    padding-left: 22px;
}
.health-box li {
    margin-bottom: 6px;
}
.health-placeholder {
    background: #f5f5f5 !important;
    border-color: #d4d4d4 !important;
    color: #1f2937 !important;
}
@media (prefers-color-scheme: dark) {
    .cell-wrapper {
        border-color: rgba(255, 255, 255, 0.45);
    }
    .health-success {
        background: rgba(74, 222, 128, 0.12);
        border-color: rgba(74, 222, 128, 0.55);
        color: #ecfdf3;
    }
    .health-fail {
        background: rgba(248, 113, 113, 0.12);
        border-color: rgba(248, 113, 113, 0.6);
        color: #fee2e2;
    }
    .health-placeholder {
        background: rgba(148, 163, 184, 0.15) !important;
        border-color: rgba(148, 163, 184, 0.4) !important;
        color: #e2e8f0 !important;
    }
}
"""


@contextmanager
def cell(title: str):
    """Context manager that renders a titled notebook-style cell.

    Usage:
        with cell("My title"):
            ...  # add components that appear inside the cell
    """
    with gr.Column(elem_classes="cell-wrapper") as column:
        gr.HTML(f"<div class='cell-title'>{title}</div>")
        yield column