Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,40 @@ import streamlit as st
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Load the text summarization pipeline
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# Load the classification pipeline
|
| 8 |
model_name2_p2 = "elozano/bert-base-cased-news-category"
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Streamlit app title
|
| 12 |
-
st.title("
|
| 13 |
|
| 14 |
# Tab layout
|
| 15 |
-
tab1, tab2 = st.tabs(["
|
| 16 |
|
| 17 |
with tab1:
|
| 18 |
-
st.header("
|
| 19 |
# Input text for summarization
|
| 20 |
-
text_to_summarize = st.text_area("Enter
|
| 21 |
-
if st.button("Summarize"):
|
| 22 |
# Perform text summarization
|
| 23 |
summary = model3_p1(text_to_summarize, max_length=130, min_length=30, do_sample=False)
|
| 24 |
# Display the summary result
|
| 25 |
st.write("Summary:", summary[0]['summary_text'])
|
| 26 |
|
| 27 |
with tab2:
|
| 28 |
-
st.header("
|
| 29 |
# Input text for news classification
|
| 30 |
-
text_to_classify = st.text_area("Enter
|
| 31 |
-
if st.button("Classify"):
|
| 32 |
-
# Perform
|
| 33 |
results = classifier(text_to_classify)[0]
|
| 34 |
# Display the classification result
|
| 35 |
max_score = float('-inf')
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Load the text summarization pipeline
|
| 5 |
+
try:
|
| 6 |
+
model3_p1 = pipeline("summarization", model="syndi-models/titlewave-t5-base")
|
| 7 |
+
except ValueError as e:
|
| 8 |
+
st.error(f"Error loading summarization model: {e}")
|
| 9 |
|
| 10 |
+
# Load the news classification pipeline
|
| 11 |
model_name2_p2 = "elozano/bert-base-cased-news-category"
|
| 12 |
+
try:
|
| 13 |
+
classifier = pipeline("text-classification", model=model_name2_p2, return_all_scores=True)
|
| 14 |
+
except ValueError as e:
|
| 15 |
+
st.error(f"Error loading classification model: {e}")
|
| 16 |
|
| 17 |
# Streamlit app title
|
| 18 |
+
st.title("Summarization and News Classification")
|
| 19 |
|
| 20 |
# Tab layout
|
| 21 |
+
tab1, tab2 = st.tabs(["Text Summarization", "News Classification"])
|
| 22 |
|
| 23 |
with tab1:
|
| 24 |
+
st.header("Text Summarization")
|
| 25 |
# Input text for summarization
|
| 26 |
+
text_to_summarize = st.text_area("Enter text to summarize:", "")
|
| 27 |
+
if st.button("Summarize") and 'model3_p1' in globals():
|
| 28 |
# Perform text summarization
|
| 29 |
summary = model3_p1(text_to_summarize, max_length=130, min_length=30, do_sample=False)
|
| 30 |
# Display the summary result
|
| 31 |
st.write("Summary:", summary[0]['summary_text'])
|
| 32 |
|
| 33 |
with tab2:
|
| 34 |
+
st.header("News Classification")
|
| 35 |
# Input text for news classification
|
| 36 |
+
text_to_classify = st.text_area("Enter text to classify:", "")
|
| 37 |
+
if st.button("Classify") and 'classifier' in globals():
|
| 38 |
+
# Perform news classification
|
| 39 |
results = classifier(text_to_classify)[0]
|
| 40 |
# Display the classification result
|
| 41 |
max_score = float('-inf')
|