Spaces:
Runtime error
Runtime error
Matthias Minder commited on
Commit ·
6ddd550
0
Parent(s):
initial commit
Browse files- .gitattributes +35 -0
- .gitignore +1 -0
- README.md +13 -0
- app.py +5 -0
- flagged/log.csv +4 -0
- requirements.txt +1 -0
- resources/interfaces/text_classification.yml +19 -0
- resources/interfaces/text_ner.yml +8 -0
- resources/tabs/app_tab.yml +3 -0
- resources/templates/template_interface.yml +20 -0
- resources/templates/template_tab.yml +3 -0
- src/ml_toolkit/wrapped_gradio_objects.py +128 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Nlp Demo
|
| 3 |
+
emoji: 👁
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.21.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.ml_toolkit.wrapped_gradio_objects import GradioTabWrapper
|
| 2 |
+
|
| 3 |
+
if __name__ == "__main__":
|
| 4 |
+
demo = GradioTabWrapper.from_yaml("resources/tabs/app_tab.yml")
|
| 5 |
+
demo.launch()
|
flagged/log.csv
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Input,Summary,flag,username,timestamp
|
| 2 |
+
Hello my name is,"Hello my name is Mark O'Keeffe, and I need to get out of here right here on the floor. I don't want this, you're not going to take my picture with the camera on you. What's taking my picture",,,2023-02-13 09:26:59.995980
|
| 3 |
+
Hello my name is,"Hello my name is Mark O'Keeffe, and I need to get out of here right here on the floor. I don't want this, you're not going to take my picture with the camera on you. What's taking my picture",,,2023-02-13 09:27:01.256913
|
| 4 |
+
Paris is the <mask> of France.,,,,,2023-02-13 14:53:47.770858
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pyyaml
|
resources/interfaces/text_classification.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
title: Text-Klassifikation
|
| 2 |
+
name: huggingface/Sahajtomar/German_Zeroshot
|
| 3 |
+
description: >
|
| 4 |
+
Bei Text-Klassifikation wollen wir einen ganzen Text einer oder mehreren Klassen zuweisen. Dazu müssen wir den Text eingeben, sowie
|
| 5 |
+
eine Liste aller möglichen Klassen. Als Resultat erhalten wir für jede Klasse die Wahrscheinlichkeit, dass der Text dazu gehört.
|
| 6 |
+
</br>
|
| 7 |
+
Das hier gezeigte Modell funktioniert nur auf Deutsch.
|
| 8 |
+
examples:
|
| 9 |
+
-
|
| 10 |
+
- >
|
| 11 |
+
Guten Tag
|
| 12 |
+
Seit dem letzten Update sind meine Pendelstrecken verschwunden und lassen sich auch nicht mehr einrichten in der App.
|
| 13 |
+
Bitte beheben
|
| 14 |
+
-
|
| 15 |
+
- zufrieden
|
| 16 |
+
- unzufrieden
|
| 17 |
+
- neutral
|
| 18 |
+
- True
|
| 19 |
+
|
resources/interfaces/text_ner.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
title: Text-Klassifikation
|
| 2 |
+
name: huggingface/manu/gliner_multi
|
| 3 |
+
description: >
|
| 4 |
+
Bei Text-Klassifikation wollen wir einen ganzen Text einer oder mehreren Klassen zuweisen. Dazu müssen wir den Text eingeben, sowie
|
| 5 |
+
eine Liste aller möglichen Klassen. Als Resultat erhalten wir für jede Klasse die Wahrscheinlichkeit, dass der Text dazu gehört.
|
| 6 |
+
</br>
|
| 7 |
+
Das hier gezeigte Modell funktioniert nur auf Deutsch.
|
| 8 |
+
|
resources/tabs/app_tab.yml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
title: GenAI Demo
|
| 2 |
+
dependencies:
|
| 3 |
+
- interfaces/text_classification.yml
|
resources/templates/template_interface.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
title: Some Title # will be used as tab title and for the link.
|
| 2 |
+
name: huggingface/deepset/gelectra-large-germanquad # path to model
|
| 3 |
+
description: > # Adding > here allows multiline strings
|
| 4 |
+
This
|
| 5 |
+
is
|
| 6 |
+
a
|
| 7 |
+
string
|
| 8 |
+
accross
|
| 9 |
+
multiple
|
| 10 |
+
lines
|
| 11 |
+
examples:
|
| 12 |
+
# This is how we can do nested lists
|
| 13 |
+
- # First example
|
| 14 |
+
- Foo
|
| 15 |
+
- Bar
|
| 16 |
+
- # Second example
|
| 17 |
+
- >
|
| 18 |
+
Hello
|
| 19 |
+
world
|
| 20 |
+
- Hello who?
|
resources/templates/template_tab.yml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
title: Some Title # will be used as tab title
|
| 2 |
+
dependencies:
|
| 3 |
+
- templates/template_interface.yaml # provide all dependant interfaces as a list
|
src/ml_toolkit/wrapped_gradio_objects.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import yaml
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
sbb = gr.themes.utils.colors.Color(
|
| 6 |
+
c50="#fff5f6",
|
| 7 |
+
c100="#ffdee2",
|
| 8 |
+
c200="#ffbdc5",
|
| 9 |
+
c300="#ff99a5",
|
| 10 |
+
c400="#f06273",
|
| 11 |
+
c500="#e0041f",
|
| 12 |
+
c600="#c20219",
|
| 13 |
+
c700="#8f0113",
|
| 14 |
+
c800="#66010d",
|
| 15 |
+
c900="#66010d",
|
| 16 |
+
c950="#66010d",
|
| 17 |
+
name="sbb",
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class BFHTheme(gr.themes.Base):
|
| 22 |
+
def __init__(
|
| 23 |
+
self,
|
| 24 |
+
):
|
| 25 |
+
super().__init__(
|
| 26 |
+
primary_hue=sbb,
|
| 27 |
+
secondary_hue=sbb,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class WrappedGradioObject:
|
| 32 |
+
def __init__(self, title, gradio_element):
|
| 33 |
+
self.title = title
|
| 34 |
+
self.gradio_element = gradio_element
|
| 35 |
+
|
| 36 |
+
def launch(self):
|
| 37 |
+
return self.gradio_element.launch()
|
| 38 |
+
|
| 39 |
+
@staticmethod
|
| 40 |
+
def read_yaml(path):
|
| 41 |
+
with open(path) as f:
|
| 42 |
+
return yaml.safe_load(f)
|
| 43 |
+
|
| 44 |
+
@staticmethod
|
| 45 |
+
def read_file(path):
|
| 46 |
+
with open(path) as f:
|
| 47 |
+
return f.read()
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class GradioInterfaceWrapper(WrappedGradioObject):
|
| 51 |
+
@classmethod
|
| 52 |
+
def from_yaml(cls, path):
|
| 53 |
+
"""Initializes Interface from YAML file."""
|
| 54 |
+
content_dict = cls.read_yaml(path)
|
| 55 |
+
return cls.create_interface(**content_dict)
|
| 56 |
+
|
| 57 |
+
@classmethod
|
| 58 |
+
def create_interface(cls, name, title, description, examples=None):
|
| 59 |
+
"""Creates Gradio-Element containing an interface."""
|
| 60 |
+
description = cls._prepend_link_to_description(name, title, description)
|
| 61 |
+
interface = gr.load(
|
| 62 |
+
name,
|
| 63 |
+
title=None, # Having the Tab-Name is sufficient.
|
| 64 |
+
description=description,
|
| 65 |
+
examples=examples,
|
| 66 |
+
)
|
| 67 |
+
return cls(title, interface)
|
| 68 |
+
|
| 69 |
+
@staticmethod
|
| 70 |
+
def _prepend_link_to_description(name, title, description):
|
| 71 |
+
without_huggingface = name.removeprefix("huggingface/")
|
| 72 |
+
link = f"https://huggingface.co/{without_huggingface}"
|
| 73 |
+
return f'<a href="{link}">{title}</a> </br> {description}'
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class GradioTabWrapper(WrappedGradioObject):
|
| 77 |
+
@classmethod
|
| 78 |
+
def from_gradio_object_list(cls, title, gradio_objects):
|
| 79 |
+
"""Constructs a GradioTabWrapper from a title and a list of WrappedGradioObjects."""
|
| 80 |
+
interface = gr.TabbedInterface(
|
| 81 |
+
[obj.gradio_element for obj in gradio_objects],
|
| 82 |
+
[obj.title for obj in gradio_objects],
|
| 83 |
+
theme=BFHTheme(),
|
| 84 |
+
)
|
| 85 |
+
return cls(title, interface)
|
| 86 |
+
|
| 87 |
+
@classmethod
|
| 88 |
+
def from_yaml(cls, path):
|
| 89 |
+
content_dict = cls.read_yaml(path)
|
| 90 |
+
gradio_objects = [
|
| 91 |
+
cls._read_dependency(dependency)
|
| 92 |
+
for dependency in content_dict["dependencies"]
|
| 93 |
+
]
|
| 94 |
+
return cls.from_gradio_object_list(
|
| 95 |
+
content_dict["title"],
|
| 96 |
+
gradio_objects,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
@staticmethod
|
| 100 |
+
def _read_dependency(path):
|
| 101 |
+
full_path = f"resources/{path}"
|
| 102 |
+
if path.startswith("interfaces"):
|
| 103 |
+
return GradioInterfaceWrapper.from_yaml(full_path)
|
| 104 |
+
if path.startswith("tabs"):
|
| 105 |
+
return GradioTabWrapper.from_yaml(full_path)
|
| 106 |
+
if path.startswith("markdown"):
|
| 107 |
+
return GradioMarkdownWrapper.from_markdown(full_path)
|
| 108 |
+
raise ValueError(
|
| 109 |
+
"Gradio Object Type could not be inferred from path name. Make sure "
|
| 110 |
+
"that all interface object yamls are in resources/interfaces, "
|
| 111 |
+
"all tab object yamls are in resources/tabs, and all markdown objects "
|
| 112 |
+
"are in resources/markdown."
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
class GradioMarkdownWrapper(WrappedGradioObject):
|
| 117 |
+
@classmethod
|
| 118 |
+
def from_markdown(cls, path):
|
| 119 |
+
"""Creates text from markdown. The title is inferred from the file name."""
|
| 120 |
+
content = cls.read_file(path)
|
| 121 |
+
title = cls.title_from_path(path)
|
| 122 |
+
return cls(title, gr.Markdown(content))
|
| 123 |
+
|
| 124 |
+
@staticmethod
|
| 125 |
+
def title_from_path(path):
|
| 126 |
+
_, last = os.path.split(path)
|
| 127 |
+
name, _ = os.path.splitext(last)
|
| 128 |
+
return name.capitalize()
|