Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,21 @@
|
|
1 |
-
# Step 2: Install the latest version of Gradio
|
2 |
-
#!pip install gradio
|
3 |
-
|
4 |
-
# Step 3: Verify the installation
|
5 |
import gradio as gr
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
# Step 4: Define the Gradio interface using the latest API
|
10 |
-
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
11 |
|
12 |
def summarize(text):
|
13 |
-
|
14 |
-
|
15 |
-
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
|
16 |
-
summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
|
17 |
-
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
18 |
-
|
19 |
-
iface1 = gr.Interface(fn=summarize, inputs="textbox", outputs="textbox", title="Text Summarizer")
|
20 |
-
iface2 = gr.Interface(fn=summarize, inputs="textbox", outputs="textbox", title="Text Summarizer")
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Step 3: Define the summarization function
|
5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
|
|
6 |
|
7 |
def summarize(text):
|
8 |
+
summary = summarizer(text, max_length=150, min_length=40, do_sample=False)
|
9 |
+
return summary[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Step 4: Create the Gradio interface
|
12 |
+
iface = gr.Interface(
|
13 |
+
fn=summarize,
|
14 |
+
inputs="textbox",
|
15 |
+
outputs="textbox",
|
16 |
+
title="Text Summarizer",
|
17 |
+
description="Summarize text using the facebook/bart-large-cnn model from Hugging Face"
|
18 |
+
)
|
19 |
|
20 |
+
# Step 5: Launch the interface
|
21 |
+
iface.launch()
|