Lord-Raven commited on
Commit
5ff29bf
·
1 Parent(s): cd2c95d

Messing with configuration.

Browse files
Files changed (2) hide show
  1. app.py +8 -8
  2. requirements.txt +1 -0
app.py CHANGED
@@ -3,8 +3,7 @@ import torch
3
  import gradio
4
  import json
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
@@ -31,16 +30,13 @@ print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
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)
39
-
40
  classifier = pipeline(task="zero-shot-classification", model=model_name, tokenizer=tokenizer_name, device="cuda:0")
41
  # classifier = pipeline(task="zero-shot-classification", model=model_name, tokenizer=tokenizer_name)
42
 
43
  def classify(data_string, request: gradio.Request):
 
44
  if request:
45
  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"]:
46
  return "{}"
@@ -52,14 +48,18 @@ def classify(data_string, request: gradio.Request):
52
  # if 'task' in data and data['task'] == 'few_shot_classification':
53
  # return few_shot_classification(data)
54
  # else:
55
- return json.dumps(zero_shot_classification(data))
 
 
 
 
 
56
 
57
  @spaces.GPU(duration=3)
58
  def zero_shot_classification(data):
59
  return classifier(data['sequence'], candidate_labels=data['candidate_labels'], hypothesis_template=data['hypothesis_template'], multi_label=data['multi_label'])
60
 
61
  def create_sequences(data):
62
- # return ['###Given:\n' + data['sequence'] + '\n###End Given\n###Hypothesis:\n' + data['hypothesis_template'].format(label) + "\n###End Hypothesis" for label in data['candidate_labels']]
63
  return [data['sequence'] + '\n' + data['hypothesis_template'].format(label) for label in data['candidate_labels']]
64
 
65
  # def few_shot_classification(data):
 
3
  import gradio
4
  import json
5
  import onnxruntime
6
+ import time
 
7
  from transformers import pipeline
8
  from fastapi import FastAPI
9
  from fastapi.middleware.cors import CORSMiddleware
 
30
  # "xenova/nli-deberta-v3-small" "cross-encoder/nli-deberta-v3-small" Was using this for a good while and it was...okay
31
 
32
  model_name = "MoritzLaurer/deberta-v3-base-zeroshot-v2.0"
 
33
  tokenizer_name = "MoritzLaurer/deberta-v3-base-zeroshot-v2.0"
34
 
 
 
 
35
  classifier = pipeline(task="zero-shot-classification", model=model_name, tokenizer=tokenizer_name, device="cuda:0")
36
  # classifier = pipeline(task="zero-shot-classification", model=model_name, tokenizer=tokenizer_name)
37
 
38
  def classify(data_string, request: gradio.Request):
39
+ print(f"classify")
40
  if request:
41
  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"]:
42
  return "{}"
 
48
  # if 'task' in data and data['task'] == 'few_shot_classification':
49
  # return few_shot_classification(data)
50
  # else:
51
+ start_time = time.time()
52
+ result = zero_shot_classification(data)
53
+ end_time = time.time()
54
+ elapsed_time = end_time - start_time
55
+ print(f"classification took {elapsed_time}.")
56
+ return json.dumps(result)
57
 
58
  @spaces.GPU(duration=3)
59
  def zero_shot_classification(data):
60
  return classifier(data['sequence'], candidate_labels=data['candidate_labels'], hypothesis_template=data['hypothesis_template'], multi_label=data['multi_label'])
61
 
62
  def create_sequences(data):
 
63
  return [data['sequence'] + '\n' + data['hypothesis_template'].format(label) for label in data['candidate_labels']]
64
 
65
  # def few_shot_classification(data):
requirements.txt CHANGED
@@ -3,5 +3,6 @@ fastapi==0.88.0
3
  huggingface_hub==0.26.0
4
  json5==0.9.25
5
  numpy
 
6
  optimum[onnxruntime-gpu]==1.24.0
7
  transformers==4.36
 
3
  huggingface_hub==0.26.0
4
  json5==0.9.25
5
  numpy
6
+ time
7
  optimum[onnxruntime-gpu]==1.24.0
8
  transformers==4.36