Spaces:
Runtime error
Runtime error
| from transformers import AutoTokenizer | |
| from transformers import AutoModelForSeq2SeqLM | |
| tokenizer = AutoTokenizer.from_pretrained("kriton/greek-text-summarization") | |
| model = AutoModelForSeq2SeqLM.from_pretrained("kriton/greek-text-summarization") | |
| from transformers import pipeline | |
| summarizer = pipeline("summarization", model="kriton/greek-text-summarization") | |
| def genarate_summary(article): | |
| inputs = tokenizer( | |
| 'summarize: ' + article, | |
| return_tensors="pt", | |
| max_length=1024, | |
| truncation=True, | |
| padding="max_length", | |
| ) | |
| outputs = model.generate( | |
| inputs["input_ids"], | |
| max_length=512, | |
| min_length=130, | |
| length_penalty=3.0, | |
| num_beams=8, | |
| early_stopping=True, | |
| repetition_penalty=3.0, | |
| ) | |
| summary = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| summary = summary[:summary.rfind('.')] | |
| return summary | |
| import gradio as gr | |
| def calculate_summary(article): | |
| return genarate_summary(article) | |
| iface = gr.Interface( | |
| fn=calculate_summary, | |
| inputs=gr.Textbox(lines=20, placeholder="Article Here", label='Article'), | |
| outputs=gr.Textbox(lines=5, placeholder="Summary", label='Summary'), | |
| btn = gr.Button("Generate") | |
| ) | |
| iface.launch() |