File size: 1,479 Bytes
945bbd0
 
 
155660f
 
 
 
 
 
945bbd0
 
1b33daa
 
 
 
 
 
 
 
155660f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b33daa
945bbd0
1b33daa
 
945bbd0
1b33daa
 
945bbd0
 
1b33daa
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import gradio as gr
from transformers import pipeline


from transformers import AutoTokenizer
from transformers import AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained("kriton/greek-text-summarization")
model = AutoModelForSeq2SeqLM.from_pretrained("kriton/greek-text-summarization")
generator = pipeline("summarization", model="kriton/greek-text-summarization")

import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load the model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("kriton/greek-text-summarization")
model = AutoModelForSeq2SeqLM.from_pretrained("kriton/greek-text-summarization")

# Define the summary generation function
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,
    )

    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Set up Gradio Interface
iface = gr.Interface(
    fn=genarate_summary, 
    inputs="text", 
    outputs="text",
    title="Greek Text Summarizer",
    description="Enter an article in Greek, and this tool will generate a summary."
)

# Launch the Gradio Interface
iface.launch()