Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Commit 
							
							·
						
						f262292
	
1
								Parent(s):
							
							c42d4c6
								
Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -18,7 +18,6 @@ model_name = "sshleifer/distill-pegasus-cnn-16-4" 
     | 
|
| 18 | 
         
             
            device = "cuda" if torch.cuda.is_available() else "cpu"
         
     | 
| 19 | 
         
             
            tokenizer = PegasusTokenizer.from_pretrained(model_name, max_length=500)
         
     | 
| 20 | 
         
             
            model = PegasusForConditionalGeneration.from_pretrained(model_name).to(device)
         
     | 
| 21 | 
         
            -
            # summarizer = pipeline(task="summarization", model=model_name, tokenizer=tokenizer, batch_size=1, device=-1)
         
     | 
| 22 | 
         | 
| 23 | 
         
             
            def summarize(slides):
         
     | 
| 24 | 
         
             
                generated_slides = copy.deepcopy(slides)
         
     | 
| 
         @@ -26,8 +25,7 @@ def summarize(slides): 
     | 
|
| 26 | 
         
             
                    for idx, (tag, content) in enumerate(contents):
         
     | 
| 27 | 
         
             
                        if tag.startswith('p'): 
         
     | 
| 28 | 
         
             
                            try:
         
     | 
| 29 | 
         
            -
                                 
     | 
| 30 | 
         
            -
                                input = tokenizer(content, truncation=True, padding="longest", return_tensors="pt")
         
     | 
| 31 | 
         
             
                                tensor = model.generate(**input)
         
     | 
| 32 | 
         
             
                                summary = tokenizer.batch_decode(tensor, skip_special_tokens=True)[0]
         
     | 
| 33 | 
         
             
                                contents[idx] = (tag, summary)
         
     | 
| 
         | 
|
| 18 | 
         
             
            device = "cuda" if torch.cuda.is_available() else "cpu"
         
     | 
| 19 | 
         
             
            tokenizer = PegasusTokenizer.from_pretrained(model_name, max_length=500)
         
     | 
| 20 | 
         
             
            model = PegasusForConditionalGeneration.from_pretrained(model_name).to(device)
         
     | 
| 
         | 
|
| 21 | 
         | 
| 22 | 
         
             
            def summarize(slides):
         
     | 
| 23 | 
         
             
                generated_slides = copy.deepcopy(slides)
         
     | 
| 
         | 
|
| 25 | 
         
             
                    for idx, (tag, content) in enumerate(contents):
         
     | 
| 26 | 
         
             
                        if tag.startswith('p'): 
         
     | 
| 27 | 
         
             
                            try:
         
     | 
| 28 | 
         
            +
                                input = tokenizer(content, truncation=True, padding="longest", return_tensors="pt").to(device)
         
     | 
| 
         | 
|
| 29 | 
         
             
                                tensor = model.generate(**input)
         
     | 
| 30 | 
         
             
                                summary = tokenizer.batch_decode(tensor, skip_special_tokens=True)[0]
         
     | 
| 31 | 
         
             
                                contents[idx] = (tag, summary)
         
     |