SuiGio commited on
Commit
920e083
·
verified ·
1 Parent(s): 77343f8

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -9
main.py CHANGED
@@ -4,16 +4,16 @@ import uvicorn
4
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
  app = FastAPI()
6
 
7
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8
- n_gpu = torch.cuda.device_count()
9
- torch.cuda.get_device_name(0)
10
  tokenizer = AutoTokenizer.from_pretrained("SuiGio/roberta_pubmesh")
11
  model = AutoModelForSequenceClassification.from_pretrained("SuiGio/roberta_pubmesh")
12
 
13
- try:
14
- model.cuda()
15
- except:
16
- pass
17
 
18
 
19
  label_names= [ "Anatomy [A]",
@@ -73,8 +73,8 @@ user_text = " BACKGROUND: The distal GI microbiota of hospitalized preterm neona
73
 
74
  def get_preds(user_text, model=model, tokenizer=tokenizer, label_names=label_names):
75
  inputs = tokenizer(user_text, padding=True, truncation=True, max_length=128, return_tensors="pt")
76
- input_ids = inputs["input_ids"].to(device)
77
- attention_mask = inputs["attention_mask"].to(device)
78
  model.eval()
79
 
80
  # Forward pass with the model
 
4
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
  app = FastAPI()
6
 
7
+ # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8
+ # n_gpu = torch.cuda.device_count()
9
+ # torch.cuda.get_device_name(0)
10
  tokenizer = AutoTokenizer.from_pretrained("SuiGio/roberta_pubmesh")
11
  model = AutoModelForSequenceClassification.from_pretrained("SuiGio/roberta_pubmesh")
12
 
13
+ # try:
14
+ # model.cuda()
15
+ # except:
16
+ # pass
17
 
18
 
19
  label_names= [ "Anatomy [A]",
 
73
 
74
  def get_preds(user_text, model=model, tokenizer=tokenizer, label_names=label_names):
75
  inputs = tokenizer(user_text, padding=True, truncation=True, max_length=128, return_tensors="pt")
76
+ input_ids = inputs["input_ids"]#.to(device)
77
+ attention_mask = inputs["attention_mask"]#.to(device)
78
  model.eval()
79
 
80
  # Forward pass with the model