Spaces:
Runtime error
Runtime error
Shift to url classifier
Browse files- .gitignore +1 -0
- app.py +26 -21
- requirements.txt +71 -70
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
env/
|
app.py
CHANGED
@@ -2,41 +2,46 @@ import gradio as gr
|
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
|
4 |
|
5 |
-
class
|
6 |
-
def __init__(self
|
7 |
-
self.model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
-
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
self.pipeline = pipeline(
|
10 |
-
"
|
11 |
-
model=
|
12 |
-
tokenizer=self.tokenizer,
|
13 |
-
return_all_scores=True,
|
14 |
)
|
|
|
|
|
15 |
|
16 |
def predict(self, input_text: str):
|
17 |
-
pred = self.pipeline(input_text)
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
return result
|
27 |
|
28 |
|
29 |
def main():
|
30 |
-
model =
|
31 |
iface = gr.Interface(
|
32 |
fn=model.predict,
|
33 |
inputs=gr.inputs.Textbox(
|
34 |
lines=3,
|
35 |
-
placeholder="
|
36 |
-
label="Input
|
37 |
),
|
38 |
outputs="label",
|
39 |
-
title="
|
40 |
examples=[
|
41 |
"I get so down when I'm alone",
|
42 |
"I believe that today everything will work out",
|
|
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
|
4 |
|
5 |
+
class UrlClassifier:
|
6 |
+
def __init__(self):
|
|
|
|
|
7 |
self.pipeline = pipeline(
|
8 |
+
"zero-shot-classification",
|
9 |
+
model="MoritzLaurer/DeBERTa-v3-large-mnli-fever-anli-ling-wanli"
|
|
|
|
|
10 |
)
|
11 |
+
self.candidate_labels = ["Apps", "Arts and Entertainment", "Automotive Ownership", "Automotive Products", "Beauty Services", "Business and Industrial", "Clothing and Accessories", "Collectables and Antiques", "Consumer Electronics", "Edible Consumer Packaged Goods", "Education and Careers", "Family and Parenting", "Finance and Insurance", "Food and Beverage Services", "Furniture", "Gifts and Holiday Items", "Hardware Supplies", "Health and Medical Services", "Hobbies and Interests", "Home and Garden Services", "Legal Services", "Life Events", "Logistics and Delivery", "Non-Profits", "Office Equipment and Supplies", "Pet Services", "Pharmaceuticals", "Real Estate", "Recreation and Fitness Activities", "Software", "Sporting Goods", "Travel and Tourism", "Web Services"]
|
12 |
+
|
13 |
|
14 |
def predict(self, input_text: str):
|
15 |
+
pred = self.pipeline(input_text, self.candidate_labels)
|
16 |
+
# pred = self.pipeline(input_text)[0]
|
17 |
+
|
18 |
+
sorted_preds = sorted(zip(pred['scores'], pred['labels']))
|
19 |
+
result = {}
|
20 |
+
for i in range(len(sorted_preds)):
|
21 |
+
result[sorted_preds[i][1]] = sorted_preds[i][0]
|
22 |
+
|
23 |
+
# result = {
|
24 |
+
# "Sadness π": pred[0]["score"],
|
25 |
+
# "Joy π": pred[1]["score"],
|
26 |
+
# "Love π": pred[2]["score"],
|
27 |
+
# "Anger π ": pred[3]["score"],
|
28 |
+
# "Fear π¨": pred[4]["score"],
|
29 |
+
# "Surprise π²": pred[5]["score"],
|
30 |
+
# }
|
31 |
return result
|
32 |
|
33 |
|
34 |
def main():
|
35 |
+
model = UrlClassifier()
|
36 |
iface = gr.Interface(
|
37 |
fn=model.predict,
|
38 |
inputs=gr.inputs.Textbox(
|
39 |
lines=3,
|
40 |
+
placeholder="Input a shopping website URL",
|
41 |
+
label="Input URL",
|
42 |
),
|
43 |
outputs="label",
|
44 |
+
title="Ecommerce URL Classification",
|
45 |
examples=[
|
46 |
"I get so down when I'm alone",
|
47 |
"I believe that today everything will work out",
|
requirements.txt
CHANGED
@@ -1,74 +1,75 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
cycler==0.11.0
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
ffmpy==0.3.
|
15 |
-
filelock==3.
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
pickleshare==0.7.5
|
46 |
-
Pillow==8.4.0
|
47 |
-
prompt-toolkit==3.0.23
|
48 |
-
ptyprocess==0.7.0
|
49 |
-
pycparser==2.21
|
50 |
-
pycryptodome==3.11.0
|
51 |
pydub==0.25.1
|
52 |
-
|
53 |
-
PyNaCl==1.4.0
|
54 |
-
pyparsing==3.0.6
|
55 |
python-dateutil==2.8.2
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
63 |
six==1.16.0
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
aiohttp==3.8.5
|
3 |
+
aiosignal==1.3.1
|
4 |
+
altair==5.1.0
|
5 |
+
annotated-types==0.5.0
|
6 |
+
anyio==3.7.1
|
7 |
+
async-timeout==4.0.3
|
8 |
+
attrs==23.1.0
|
9 |
+
certifi==2023.7.22
|
10 |
+
charset-normalizer==3.2.0
|
11 |
+
click==8.1.7
|
12 |
+
contourpy==1.1.0
|
13 |
cycler==0.11.0
|
14 |
+
datasets==2.14.4
|
15 |
+
dill==0.3.7
|
16 |
+
fastapi==0.103.0
|
17 |
+
ffmpy==0.3.1
|
18 |
+
filelock==3.12.3
|
19 |
+
fonttools==4.42.1
|
20 |
+
frozenlist==1.4.0
|
21 |
+
fsspec==2023.6.0
|
22 |
+
gradio==3.41.2
|
23 |
+
gradio_client==0.5.0
|
24 |
+
h11==0.14.0
|
25 |
+
httpcore==0.17.3
|
26 |
+
httpx==0.24.1
|
27 |
+
huggingface-hub==0.16.4
|
28 |
+
idna==3.4
|
29 |
+
importlib-resources==6.0.1
|
30 |
+
Jinja2==3.1.2
|
31 |
+
jsonschema==4.19.0
|
32 |
+
jsonschema-specifications==2023.7.1
|
33 |
+
kiwisolver==1.4.5
|
34 |
+
MarkupSafe==2.1.3
|
35 |
+
matplotlib==3.7.2
|
36 |
+
mpmath==1.3.0
|
37 |
+
multidict==6.0.4
|
38 |
+
multiprocess==0.70.15
|
39 |
+
networkx==3.1
|
40 |
+
numpy==1.25.2
|
41 |
+
orjson==3.9.5
|
42 |
+
packaging==23.1
|
43 |
+
pandas==2.0.3
|
44 |
+
Pillow==10.0.0
|
45 |
+
pyarrow==13.0.0
|
46 |
+
pydantic==2.3.0
|
47 |
+
pydantic_core==2.6.3
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
pydub==0.25.1
|
49 |
+
pyparsing==3.0.9
|
|
|
|
|
50 |
python-dateutil==2.8.2
|
51 |
+
python-multipart==0.0.6
|
52 |
+
pytz==2023.3
|
53 |
+
PyYAML==6.0.1
|
54 |
+
referencing==0.30.2
|
55 |
+
regex==2023.8.8
|
56 |
+
requests==2.31.0
|
57 |
+
rpds-py==0.10.0
|
58 |
+
safetensors==0.3.3
|
59 |
+
semantic-version==2.10.0
|
60 |
six==1.16.0
|
61 |
+
sniffio==1.3.0
|
62 |
+
starlette==0.27.0
|
63 |
+
sympy==1.12
|
64 |
+
tokenizers==0.13.3
|
65 |
+
toolz==0.12.0
|
66 |
+
torch==2.0.1
|
67 |
+
tqdm==4.66.1
|
68 |
+
transformers==4.32.1
|
69 |
+
typing_extensions==4.7.1
|
70 |
+
tzdata==2023.3
|
71 |
+
urllib3==2.0.4
|
72 |
+
uvicorn==0.23.2
|
73 |
+
websockets==11.0.3
|
74 |
+
xxhash==3.3.0
|
75 |
+
yarl==1.9.2
|