File size: 1,160 Bytes
c968e7e
 
 
 
 
8baa175
c968e7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8baa175
c968e7e
8baa175
 
c968e7e
 
 
 
 
 
8baa175
c968e7e
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
import gradio as gr
import json
import yaml


class GradioElementWrapper:
    def __init__(self, title, gradio_element):
        self.title = title
        self.gradio_element = gradio_element

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

    @classmethod
    def create_interface(cls, name, title, description, examples=None):
        """Creates Gradio-Element containing an interface."""
        description = cls._prepend_link_to_description(name, title, description)
        element = gr.load(
            name,
            title=None,  # Having the Tab-Name is sufficient.
            description=description,
            examples=examples,
        )
        return cls(title, element)

    @staticmethod
    def _prepend_link_to_description(name, title, description):
        without_huggingface = name.removeprefix("huggingface/")
        link = f"https://huggingface.co/{without_huggingface}"
        return f'<a href="{link}">{title}</a> </br> {description}'