maettubfh
reformatted with black
8baa175
raw
history blame
1.16 kB
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}'