Spaces:
Sleeping
Sleeping
import gradio as gr | |
import json | |
import yaml | |
class GradioElementWrapper: | |
def __init__(self, title, gradio_element): | |
self.title = title | |
self.gradio_element = gradio_element | |
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) | |
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) | |
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}' | |