Spaces:
Running
on
Zero
Running
on
Zero
Lord-Raven
commited on
Commit
·
3f34143
1
Parent(s):
02f2915
Messing with configuration.
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import torch
|
|
5 |
import onnxruntime
|
6 |
from optimum.onnxruntime import ORTModelForSequenceClassification
|
7 |
from transformers import AutoTokenizer
|
8 |
-
from
|
9 |
from fastapi import FastAPI
|
10 |
from fastapi.middleware.cors import CORSMiddleware
|
11 |
|
@@ -30,9 +30,9 @@ print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
|
30 |
# "Xenova/deBERTa-v3-base-mnli" "MoritzLaurer/DeBERTa-v3-base-mnli" Still a bit slow and not great answers
|
31 |
# "xenova/nli-deberta-v3-small" "cross-encoder/nli-deberta-v3-small" Was using this for a good while and it was...okay
|
32 |
|
33 |
-
|
34 |
# file_name = "onnx/model.onnx"
|
35 |
-
|
36 |
|
37 |
# model = ORTModelForSequenceClassification.from_pretrained(model_name, export=True, provider="CUDAExecutionProvider")
|
38 |
# tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, model_max_length=512)
|
@@ -40,20 +40,21 @@ print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
|
40 |
session_options = onnxruntime.SessionOptions()
|
41 |
session_options.log_severity_level = 0
|
42 |
|
43 |
-
print(f"ORTModelForSequenceClassification.from_pretrained")
|
44 |
-
model = ORTModelForSequenceClassification.from_pretrained(
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
)
|
50 |
-
print(f"AutoTokenizer.from_pretrained")
|
51 |
-
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
52 |
|
53 |
-
|
|
|
54 |
|
55 |
print(f"Testing 1")
|
56 |
-
@spaces.GPU
|
57 |
def classify(data_string, request: gradio.Request):
|
58 |
if request:
|
59 |
if request.headers["origin"] not in ["https://statosphere-3704059fdd7e.c5v4v4jx6pq5.win", "https://crunchatize-77a78ffcc6a6.c5v4v4jx6pq5.win", "https://crunchatize-2-2b4f5b1479a6.c5v4v4jx6pq5.win", "https://tamabotchi-2dba63df3bf1.c5v4v4jx6pq5.win", "https://ravenok-statosphere-backend.hf.space", "https://lord-raven.github.io"]:
|
@@ -66,8 +67,7 @@ def classify(data_string, request: gradio.Request):
|
|
66 |
|
67 |
print(f"Testing 2")
|
68 |
def zero_shot_classification(data):
|
69 |
-
results = []
|
70 |
-
# classifier(data['sequence'], candidate_labels=data['candidate_labels'], hypothesis_template=data['hypothesis_template'], multi_label=data['multi_label'])
|
71 |
response_string = json.dumps(results)
|
72 |
return response_string
|
73 |
|
|
|
5 |
import onnxruntime
|
6 |
from optimum.onnxruntime import ORTModelForSequenceClassification
|
7 |
from transformers import AutoTokenizer
|
8 |
+
from transformers import pipeline
|
9 |
from fastapi import FastAPI
|
10 |
from fastapi.middleware.cors import CORSMiddleware
|
11 |
|
|
|
30 |
# "Xenova/deBERTa-v3-base-mnli" "MoritzLaurer/DeBERTa-v3-base-mnli" Still a bit slow and not great answers
|
31 |
# "xenova/nli-deberta-v3-small" "cross-encoder/nli-deberta-v3-small" Was using this for a good while and it was...okay
|
32 |
|
33 |
+
model_name = "MoritzLaurer/deberta-v3-base-zeroshot-v2.0"
|
34 |
# file_name = "onnx/model.onnx"
|
35 |
+
tokenizer_name = "MoritzLaurer/deberta-v3-base-zeroshot-v2.0"
|
36 |
|
37 |
# model = ORTModelForSequenceClassification.from_pretrained(model_name, export=True, provider="CUDAExecutionProvider")
|
38 |
# tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, model_max_length=512)
|
|
|
40 |
session_options = onnxruntime.SessionOptions()
|
41 |
session_options.log_severity_level = 0
|
42 |
|
43 |
+
# print(f"ORTModelForSequenceClassification.from_pretrained")
|
44 |
+
# model = ORTModelForSequenceClassification.from_pretrained(
|
45 |
+
# "distilbert-base-uncased-finetuned-sst-2-english",
|
46 |
+
# export=True,
|
47 |
+
# provider="CUDAExecutionProvider",
|
48 |
+
# session_options=session_options
|
49 |
+
# )
|
50 |
+
# print(f"AutoTokenizer.from_pretrained")
|
51 |
+
# tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
52 |
|
53 |
+
print(f"pipeline")
|
54 |
+
classifier = pipeline(task="zero-shot-classification", model=model_name, tokenizer=tokenizer_name, device="cuda:0")
|
55 |
|
56 |
print(f"Testing 1")
|
57 |
+
@spaces.GPU
|
58 |
def classify(data_string, request: gradio.Request):
|
59 |
if request:
|
60 |
if request.headers["origin"] not in ["https://statosphere-3704059fdd7e.c5v4v4jx6pq5.win", "https://crunchatize-77a78ffcc6a6.c5v4v4jx6pq5.win", "https://crunchatize-2-2b4f5b1479a6.c5v4v4jx6pq5.win", "https://tamabotchi-2dba63df3bf1.c5v4v4jx6pq5.win", "https://ravenok-statosphere-backend.hf.space", "https://lord-raven.github.io"]:
|
|
|
67 |
|
68 |
print(f"Testing 2")
|
69 |
def zero_shot_classification(data):
|
70 |
+
results = classifier(data['sequence'], candidate_labels=data['candidate_labels'], hypothesis_template=data['hypothesis_template'], multi_label=data['multi_label'])
|
|
|
71 |
response_string = json.dumps(results)
|
72 |
return response_string
|
73 |
|