update code
Browse files- README.md +1 -0
- handler.py +6 -8
- requirements.txt +1 -2
    	
        README.md
    CHANGED
    
    | @@ -3,6 +3,7 @@ inference: false | |
| 3 | 
             
            tags:
         | 
| 4 | 
             
            - musicgen
         | 
| 5 | 
             
            license: cc-by-nc-4.0
         | 
|  | |
| 6 | 
             
            ---
         | 
| 7 |  | 
| 8 | 
             
            # MusicGen - Small - 300M
         | 
|  | |
| 3 | 
             
            tags:
         | 
| 4 | 
             
            - musicgen
         | 
| 5 | 
             
            license: cc-by-nc-4.0
         | 
| 6 | 
            +
            duplicated_from: facebook/musicgen-small
         | 
| 7 | 
             
            ---
         | 
| 8 |  | 
| 9 | 
             
            # MusicGen - Small - 300M
         | 
    	
        handler.py
    CHANGED
    
    | @@ -3,10 +3,10 @@ from transformers import AutoProcessor, MusicgenForConditionalGeneration | |
| 3 | 
             
            import torch
         | 
| 4 |  | 
| 5 | 
             
            class EndpointHandler:
         | 
| 6 | 
            -
                def __init__(self, path=" | 
| 7 | 
             
                    # load model and processor from path
         | 
| 8 | 
             
                    self.processor = AutoProcessor.from_pretrained(path)
         | 
| 9 | 
            -
                    self.model = MusicgenForConditionalGeneration.from_pretrained(path | 
| 10 |  | 
| 11 | 
             
                def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
         | 
| 12 | 
             
                    """
         | 
| @@ -26,13 +26,11 @@ class EndpointHandler: | |
| 26 |  | 
| 27 | 
             
                    # pass inputs with all kwargs in data
         | 
| 28 | 
             
                    if parameters is not None:
         | 
| 29 | 
            -
                         | 
| 30 | 
            -
                            outputs = self.model.generate(**inputs,do_sample=True, guidance_scale=3, max_new_tokens=256, **parameters)
         | 
| 31 | 
             
                    else:
         | 
| 32 | 
            -
                         | 
| 33 | 
            -
                            outputs = self.model.generate(**inputs,do_sample=True, guidance_scale=3, max_new_tokens=256)
         | 
| 34 |  | 
| 35 | 
             
                    # postprocess the prediction
         | 
| 36 | 
            -
                    prediction = outputs[0].cpu().numpy() | 
| 37 |  | 
| 38 | 
            -
                    return [{" | 
|  | |
| 3 | 
             
            import torch
         | 
| 4 |  | 
| 5 | 
             
            class EndpointHandler:
         | 
| 6 | 
            +
                def __init__(self, path=""):
         | 
| 7 | 
             
                    # load model and processor from path
         | 
| 8 | 
             
                    self.processor = AutoProcessor.from_pretrained(path)
         | 
| 9 | 
            +
                    self.model = MusicgenForConditionalGeneration.from_pretrained(path).to("cuda")
         | 
| 10 |  | 
| 11 | 
             
                def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
         | 
| 12 | 
             
                    """
         | 
|  | |
| 26 |  | 
| 27 | 
             
                    # pass inputs with all kwargs in data
         | 
| 28 | 
             
                    if parameters is not None:
         | 
| 29 | 
            +
                        outputs = self.model.generate(**inputs, max_new_tokens=256, **parameters)
         | 
|  | |
| 30 | 
             
                    else:
         | 
| 31 | 
            +
                        outputs = self.model.generate(**inputs, max_new_tokens=256)
         | 
|  | |
| 32 |  | 
| 33 | 
             
                    # postprocess the prediction
         | 
| 34 | 
            +
                    prediction = outputs[0].cpu().numpy()
         | 
| 35 |  | 
| 36 | 
            +
                    return [{"generated_text": prediction}]
         | 
    	
        requirements.txt
    CHANGED
    
    | @@ -1,3 +1,2 @@ | |
| 1 | 
             
            transformers==4.31.0
         | 
| 2 | 
            -
            accelerate>=0.20.3
         | 
| 3 | 
            -
             | 
|  | |
| 1 | 
             
            transformers==4.31.0
         | 
| 2 | 
            +
            accelerate>=0.20.3
         | 
|  |