Upload folder using huggingface_hub

#2
by 0xBreath - opened
Files changed (1) hide show
  1. handler.py +7 -3
handler.py CHANGED
@@ -2,7 +2,6 @@ from typing import Dict, List, Any
2
  import torch
3
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
4
  import logging
5
- logger = logging.getLogger(__name__)
6
 
7
 
8
  class EndpointHandler:
@@ -11,9 +10,14 @@ class EndpointHandler:
11
  self.model = AutoModelForCausalLM.from_pretrained(path, device_map="auto", load_in_8bit=True)
12
  self.tokenizer = AutoTokenizer.from_pretrained(path)
13
  self.pipe = pipeline("text-generation", self.model, self.tokenizer)
 
 
 
 
 
14
 
15
  def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
16
- logger.info("CALL DATA:", data)
17
 
18
  # process input
19
  inputs = data.pop("inputs", data)
@@ -25,6 +29,6 @@ class EndpointHandler:
25
  output = self.pipe(inputs)
26
 
27
  response = output[0]['generated_text'][-1]
28
- logger.info("RESPONSE:", response)
29
 
30
  return {"generated_text": response}
 
2
  import torch
3
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
4
  import logging
 
5
 
6
 
7
  class EndpointHandler:
 
10
  self.model = AutoModelForCausalLM.from_pretrained(path, device_map="auto", load_in_8bit=True)
11
  self.tokenizer = AutoTokenizer.from_pretrained(path)
12
  self.pipe = pipeline("text-generation", self.model, self.tokenizer)
13
+ logging.basicConfig(
14
+ level=logging.INFO,
15
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
16
+ )
17
+ self.logger = logging.getLogger(__name__)
18
 
19
  def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
20
+ self.logger.info("CALL DATA:", data)
21
 
22
  # process input
23
  inputs = data.pop("inputs", data)
 
29
  output = self.pipe(inputs)
30
 
31
  response = output[0]['generated_text'][-1]
32
+ self.logger.info("RESPONSE:", response)
33
 
34
  return {"generated_text": response}