Spaces:
Sleeping
Sleeping
smellslikeml
commited on
Commit
•
7f9e237
1
Parent(s):
f723b1f
first commit
Browse files- README.md +6 -0
- app.py +4 -0
- classifier_labeler.py +25 -0
- requirements.txt +3 -0
- tool_config.json +5 -0
README.md
CHANGED
@@ -10,4 +10,10 @@ pinned: false
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
+
Make sure to set you API key as an environment variable:
|
14 |
+
```
|
15 |
+
export REMYXAI_API_KEY=<your-key-here>
|
16 |
+
```
|
17 |
+
|
18 |
+
Read more: https://github.com/remyxai/remyxai-cli
|
19 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers.tools.base import launch_gradio_demo
|
2 |
+
from classifier_labeler import RemyxClassifier
|
3 |
+
|
4 |
+
launch_gradio_demo(RemyxClassifier)
|
classifier_labeler.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import Tool
|
2 |
+
from remyxai.utils import labeler
|
3 |
+
|
4 |
+
class RemyxClassifier(Tool):
|
5 |
+
name = "custom_classifier"
|
6 |
+
description = (
|
7 |
+
"""
|
8 |
+
This is a tool that fetches or trains a custom classifier
|
9 |
+
and returns a json file containing the labels of the images in a directory.
|
10 |
+
It takes an image directory and a comma separated string of labels
|
11 |
+
as input, and returns the json file containing the predicted labels
|
12 |
+
for each image as output
|
13 |
+
"""
|
14 |
+
)
|
15 |
+
|
16 |
+
inputs = ["text", "text"]
|
17 |
+
outputs = ["text"]
|
18 |
+
|
19 |
+
def __call__(self, image_directory: str, labels: str):
|
20 |
+
labels_list = [l.strip() for l in labels.split(",")]
|
21 |
+
model_name = "labeler_{}".format("_".join(labels_list))
|
22 |
+
result = labeler(labels=labels_list,
|
23 |
+
image_dir=image_directory,
|
24 |
+
model_name=model_name)
|
25 |
+
return result
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
remyxai
|
2 |
+
huggingface_hub
|
3 |
+
transformers
|
tool_config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"description": "This is a tool that fetches or trains a custom classifier and returns a json file containing the labels of the images in a directory. It takes an image directory and a comma separated string of labels as input, and returns the json file containing the predicted labels for each image as output",
|
3 |
+
"name": "custom_classifier",
|
4 |
+
"tool_class": "classifier_labeler.RemyxClassifier"
|
5 |
+
}
|