Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
|
4 |
# Load the model and tokenizer
|
5 |
-
|
6 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(
|
|
|
7 |
|
8 |
# Set up the summarizer pipeline
|
9 |
-
summarizer = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Define the summarization function
|
12 |
-
def generate_summary(
|
13 |
-
|
14 |
-
|
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, #
|
36 |
-
inputs=gr.Textbox(label="
|
37 |
-
outputs=gr.Textbox(label="Summary"
|
38 |
-
|
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()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
3 |
|
4 |
# Load the model and tokenizer
|
5 |
+
model_name = 'IMISLab/GreekWiki-umt5-base'
|
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=220,
|
16 |
+
truncation=True
|
17 |
+
)
|
18 |
|
19 |
# Define the summarization function
|
20 |
+
def generate_summary(text):
|
21 |
+
output = summarizer('summarize: ' + text)
|
22 |
+
return output[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Create Gradio interface
|
25 |
iface = gr.Interface(
|
26 |
+
fn=generate_summary, # The function that Gradio will use
|
27 |
+
inputs=gr.Textbox(label="Input Text", lines=5, placeholder="Enter the text to summarize..."),
|
28 |
+
outputs=gr.Textbox(label="Summary"),
|
29 |
+
live=True
|
|
|
|
|
30 |
)
|
31 |
|
32 |
+
# Launch the Gradio interface
|
33 |
iface.launch()
|