Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,84 +1,44 @@
|
|
1 |
-
# import gradio as gr
|
2 |
-
# from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
3 |
-
|
4 |
-
# # Load the model and tokenizer
|
5 |
-
# model_name = 'IMISLab/GreekT5-umt5-base-greeksum'
|
6 |
-
# model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
7 |
-
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
-
|
9 |
-
# # Set up the summarizer pipeline
|
10 |
-
# summarizer = pipeline(
|
11 |
-
# 'summarization',
|
12 |
-
# model=model,
|
13 |
-
# tokenizer=tokenizer,
|
14 |
-
# device=-1, # -1 for CPU; set to 0 for GPU if available
|
15 |
-
# max_new_tokens=128,
|
16 |
-
# truncation=True
|
17 |
-
# )
|
18 |
-
|
19 |
-
# # Define the summarization function
|
20 |
-
# def summarize_text(text):
|
21 |
-
# output = summarizer('summarize: ' + text)
|
22 |
-
# return output[0]['summary_text']
|
23 |
-
|
24 |
-
# # Create a Gradio interface
|
25 |
-
# iface = gr.Interface(
|
26 |
-
# fn=summarize_text, # Function to run
|
27 |
-
# inputs=gr.Textbox(label="Enter Greek Text", placeholder="Type or paste your text here..."), # Input component
|
28 |
-
# outputs=gr.Textbox(label="Summary", interactive=True), # Output component
|
29 |
-
# title="Greek Text Summarization", # Title for the UI
|
30 |
-
# description="This app uses a pre-trained Greek summarization model to generate a brief summary of your input text.", # Description
|
31 |
-
# allow_flagging="never" # Optional: Disable flagging feature
|
32 |
-
# )
|
33 |
-
|
34 |
-
# # Launch the interface
|
35 |
-
# iface.launch()
|
36 |
-
|
37 |
import gradio as gr
|
38 |
-
from transformers import pipeline
|
39 |
-
|
40 |
-
# Load the
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
iface = gr.Interface(
|
50 |
-
fn=
|
51 |
-
inputs=gr.Textbox(label="Enter Article
|
52 |
outputs=gr.Textbox(label="Summary", interactive=True), # Output component
|
53 |
-
title="Text Summarization", # Title
|
54 |
-
description="This app uses a pre-trained summarization model
|
55 |
-
allow_flagging="never" # Disable flagging
|
56 |
)
|
57 |
|
58 |
# Launch the interface
|
59 |
iface.launch()
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
+
|
4 |
+
# Load the model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("kriton/greek-text-summarization")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("kriton/greek-text-summarization")
|
7 |
+
|
8 |
+
# Set up the summarizer pipeline
|
9 |
+
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
10 |
+
|
11 |
+
# Define the summarization function
|
12 |
+
def generate_summary(article):
|
13 |
+
inputs = tokenizer(
|
14 |
+
'summarize: ' + article,
|
15 |
+
return_tensors="pt",
|
16 |
+
max_length=1024,
|
17 |
+
truncation=True,
|
18 |
+
padding="max_length",
|
19 |
+
)
|
20 |
+
|
21 |
+
outputs = model.generate(
|
22 |
+
inputs["input_ids"],
|
23 |
+
max_length=512,
|
24 |
+
min_length=130,
|
25 |
+
length_penalty=3.0,
|
26 |
+
num_beams=8,
|
27 |
+
early_stopping=True,
|
28 |
+
repetition_penalty=3.0,
|
29 |
+
)
|
30 |
+
|
31 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
32 |
+
|
33 |
+
# Create Gradio interface
|
34 |
iface = gr.Interface(
|
35 |
+
fn=generate_summary, # Function to run
|
36 |
+
inputs=gr.Textbox(label="Enter Greek Article", placeholder="Type or paste your article here..."), # Input component
|
37 |
outputs=gr.Textbox(label="Summary", interactive=True), # Output component
|
38 |
+
title="Greek Text Summarization", # Title for the UI
|
39 |
+
description="This app uses a pre-trained Greek summarization model to generate a brief summary of your input text.", # Description
|
40 |
+
allow_flagging="never" # Optional: Disable flagging feature
|
41 |
)
|
42 |
|
43 |
# Launch the interface
|
44 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|