File size: 1,594 Bytes
a3e0cd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import yaml
from gradio.themes.utils import colors


bfh_blue = colors.Color(
    c50="#edf0f2",
    c100="#dbe0e5",
    c200="#b7c1cb",
    c300="#93a2b1",
    c400="#6f8397",
    c500="#4b647d",
    c600="#3c5064",
    c700="#2d3c4b",
    c800="#1e2832",
    c900="#0f1419",
    c950="#070a0c",
    name="bfh_blue",
)

bfh_yellow = colors.Color(
    c50="#fff9e6",
    c100="#fef3cc",
    c200="#fde799",
    c300="#fcdb66",
    c400="#fbcf33",
    c500="#fac300",
    c600="#c89c00",
    c700="#967500",
    c800="#644e00",
    c900="#322700",
    c950="#191300",
    name="bfh_yellow",
)


class BFHTheme(gr.themes.Base):
    def __init__(
        self,
    ):
        super().__init__(
            primary_hue=bfh_blue,
            secondary_hue=bfh_yellow,
        )

class InterfaceCreator:
    @staticmethod
    def read_yaml(path):
        with open(path) as f:
            return yaml.safe_load(f)
    @classmethod
    def from_yaml(cls, path):
        """Initializes Interface from YAML file."""
        content_dict = cls.read_yaml(path)
        return cls.create_interface(**content_dict)

    @classmethod
    def create_interface(cls, name, title=None, description=None, examples=None):
        """Creates Gradio-Element containing an interface."""
        interface = gr.load(
            name,
            title=None,
            description=description,
            examples=examples,
            theme=BFHTheme(),
        )
        return interface


if __name__=="__main__":
    interface = InterfaceCreator.from_yaml("config.yml")
    interface.launch()