Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
|
5 |
+
# Function to load the model
|
6 |
+
@st.cache(allow_output_mutation=True)
|
7 |
+
def load_model():
|
8 |
+
summarizer = pipeline("text2text-generation", model="pk248/pegasus-samsum")
|
9 |
+
return summarizer
|
10 |
+
|
11 |
+
|
12 |
+
# Load the model
|
13 |
+
model = load_model()
|
14 |
+
|
15 |
+
# Streamlit UI
|
16 |
+
st.title("Text Summarization App")
|
17 |
+
st.write("This app uses the pk248/pegasus-samsum model to summarize text.")
|
18 |
+
|
19 |
+
# Text input
|
20 |
+
user_input = st.text_area("Enter text to summarize:", height=200)
|
21 |
+
|
22 |
+
# Summarize button
|
23 |
+
if st.button("Summarize"):
|
24 |
+
if user_input:
|
25 |
+
# Model inference
|
26 |
+
summary = model(user_input, max_length=100, min_length=5, length_penalty=2.0)
|
27 |
+
st.write(summary[0]["generated_text"])
|
28 |
+
else:
|
29 |
+
st.write("Please enter some text to summarize.")
|