Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app.py +48 -13
- model/config.json +1 -1
- model/pytorch_model.bin +1 -1
- serve.yaml +12 -11
app.py
CHANGED
@@ -1,31 +1,37 @@
|
|
1 |
# Apache Software License 2.0
|
2 |
-
#
|
3 |
# Copyright (c) ZenML GmbH 2023. All rights reserved.
|
4 |
-
#
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
# you may not use this file except in compliance with the License.
|
7 |
# You may obtain a copy of the License at
|
8 |
-
#
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
-
#
|
11 |
# Unless required by applicable law or agreed to in writing, software
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
# See the License for the specific language governing permissions and
|
15 |
# limitations under the License.
|
16 |
-
|
|
|
17 |
|
18 |
import click
|
19 |
import numpy as np
|
20 |
-
import os
|
21 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
22 |
-
from os.path import dirname
|
23 |
|
24 |
import gradio as gr
|
25 |
|
|
|
26 |
@click.command()
|
27 |
-
@click.option(
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
@click.option(
|
30 |
"--labels", default="Negative,Positive", help="Comma-separated list of labels."
|
31 |
)
|
@@ -34,7 +40,7 @@ import gradio as gr
|
|
34 |
)
|
35 |
@click.option(
|
36 |
"--description",
|
37 |
-
default="Sentiment
|
38 |
help="Description of the Gradio interface.",
|
39 |
)
|
40 |
@click.option(
|
@@ -45,15 +51,44 @@ import gradio as gr
|
|
45 |
@click.option(
|
46 |
"--examples",
|
47 |
default="This is an awesome journey, I love it!",
|
48 |
-
help="
|
49 |
)
|
50 |
def sentiment_analysis(
|
51 |
-
tokenizer_name_or_path
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
labels = labels.split(",")
|
54 |
examples = [examples]
|
55 |
|
56 |
-
def preprocess(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
new_text = []
|
58 |
for t in text.split(" "):
|
59 |
t = "@user" if t.startswith("@") and len(t) > 1 else t
|
|
|
1 |
# Apache Software License 2.0
|
2 |
+
#
|
3 |
# Copyright (c) ZenML GmbH 2023. All rights reserved.
|
4 |
+
#
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
# you may not use this file except in compliance with the License.
|
7 |
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
# Unless required by applicable law or agreed to in writing, software
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
# See the License for the specific language governing permissions and
|
15 |
# limitations under the License.
|
16 |
+
from os.path import dirname
|
17 |
+
from typing import Optional
|
18 |
|
19 |
import click
|
20 |
import numpy as np
|
|
|
21 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
22 |
|
23 |
import gradio as gr
|
24 |
|
25 |
+
|
26 |
@click.command()
|
27 |
+
@click.option(
|
28 |
+
"--tokenizer_name_or_path",
|
29 |
+
default="tokenizer",
|
30 |
+
help="Name or the path of the tokenizer.",
|
31 |
+
)
|
32 |
+
@click.option(
|
33 |
+
"--model_name_or_path", default="model", help="Name or the path of the model."
|
34 |
+
)
|
35 |
@click.option(
|
36 |
"--labels", default="Negative,Positive", help="Comma-separated list of labels."
|
37 |
)
|
|
|
40 |
)
|
41 |
@click.option(
|
42 |
"--description",
|
43 |
+
default="Text Classification - Sentiment Analysis - ZenML - Gradio",
|
44 |
help="Description of the Gradio interface.",
|
45 |
)
|
46 |
@click.option(
|
|
|
51 |
@click.option(
|
52 |
"--examples",
|
53 |
default="This is an awesome journey, I love it!",
|
54 |
+
help="An example to show in the Gradio interface.",
|
55 |
)
|
56 |
def sentiment_analysis(
|
57 |
+
tokenizer_name_or_path: Optional[str],
|
58 |
+
model_name_or_path: Optional[str],
|
59 |
+
labels: Optional[str],
|
60 |
+
title: Optional[str],
|
61 |
+
description: Optional[str],
|
62 |
+
interpretation: Optional[str],
|
63 |
+
examples: Optional[str],
|
64 |
):
|
65 |
+
"""Launches a Gradio interface for sentiment analysis.
|
66 |
+
|
67 |
+
This function launches a Gradio interface for text-classification.
|
68 |
+
It loads a model and a tokenizer from the provided paths and uses
|
69 |
+
them to predict the sentiment of the input text.
|
70 |
+
|
71 |
+
Args:
|
72 |
+
tokenizer_name_or_path (str): Name or the path of the tokenizer.
|
73 |
+
model_name_or_path (str): Name or the path of the model.
|
74 |
+
labels (str): Comma-separated list of labels.
|
75 |
+
title (str): Title of the Gradio interface.
|
76 |
+
description (str): Description of the Gradio interface.
|
77 |
+
interpretation (str): Interpretation mode for the Gradio interface.
|
78 |
+
examples (str): Comma-separated list of examples to show in the Gradio interface.
|
79 |
+
"""
|
80 |
labels = labels.split(",")
|
81 |
examples = [examples]
|
82 |
|
83 |
+
def preprocess(text: str) -> str:
|
84 |
+
"""Preprocesses the text.
|
85 |
+
|
86 |
+
Args:
|
87 |
+
text (str): Input text.
|
88 |
+
|
89 |
+
Returns:
|
90 |
+
str: Preprocessed text.
|
91 |
+
"""
|
92 |
new_text = []
|
93 |
for t in text.split(" "):
|
94 |
t = "@user" if t.startswith("@") and len(t) > 1 else t
|
model/config.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
{
|
2 |
-
"_name_or_path": "/
|
3 |
"architectures": [
|
4 |
"RobertaForSequenceClassification"
|
5 |
],
|
|
|
1 |
{
|
2 |
+
"_name_or_path": "/var/folders/lt/r3j8hp4s00dfgtf662d1prw80000gp/T/tmp7zaefx9s",
|
3 |
"architectures": [
|
4 |
"RobertaForSequenceClassification"
|
5 |
],
|
model/pytorch_model.bin
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 498655278
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:725bbeee72c1021836a2417dd029c13df44d2b0c6becd17c207e597ae6c078d6
|
3 |
size 498655278
|
serve.yaml
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
# Task name (optional), used for display purposes.
|
2 |
-
name:
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Working directory (optional), synced to ~/sky_workdir on the remote cluster
|
5 |
# each time launch or exec is run with the yaml file.
|
6 |
#
|
@@ -16,13 +25,5 @@ setup: |
|
|
16 |
echo "Setup complete."
|
17 |
|
18 |
run: |
|
19 |
-
|
20 |
-
|
21 |
-
python -u -m app.py \
|
22 |
-
----tokenizer_name $MODEL_NAME \
|
23 |
-
--tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
|
24 |
-
--tokenizer hf-internal-testing/llama-tokenizer 2>&1 | tee api_server.log &
|
25 |
-
echo 'Waiting for vllm api server to start...'
|
26 |
-
while ! `cat api_server.log | grep -q 'Uvicorn running on'`; do sleep 1; done
|
27 |
-
echo 'Starting gradio server...'
|
28 |
-
python vllm/examples/gradio_webserver.py
|
|
|
1 |
# Task name (optional), used for display purposes.
|
2 |
+
name: ZenML NLP project}
|
3 |
|
4 |
+
resources:
|
5 |
+
cloud: aws # The cloud to use (optional).
|
6 |
+
|
7 |
+
# The region to use (optional). Auto-failover will be disabled
|
8 |
+
# if this is specified.
|
9 |
+
region: us-east-1
|
10 |
+
|
11 |
+
# The instance type to use (optional).
|
12 |
+
instance_type: t3.large
|
13 |
# Working directory (optional), synced to ~/sky_workdir on the remote cluster
|
14 |
# each time launch or exec is run with the yaml file.
|
15 |
#
|
|
|
25 |
echo "Setup complete."
|
26 |
|
27 |
run: |
|
28 |
+
echo 'Starting gradio app...'
|
29 |
+
python app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|