demo-llama / app.py
maettubfh's picture
added small application
a3e0cd8
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()