Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,43 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the text summarization pipeline
|
| 5 |
+
model3_p1 = pipeline("summarization", model="syndi-models/titlewave-t5-base")
|
| 6 |
+
|
| 7 |
+
# Load the classification pipeline
|
| 8 |
+
model_name2_p2 = "elozano/bert-base-cased-news-category"
|
| 9 |
+
classifier = pipeline("text-classification", model=model_name2_p2, return_all_scores=True)
|
| 10 |
+
|
| 11 |
+
# Streamlit app title
|
| 12 |
+
st.title("Question Summarization and Classification")
|
| 13 |
+
|
| 14 |
+
# Tab layout
|
| 15 |
+
tab1, tab2 = st.tabs(["Question Summarization", "Question Classification"])
|
| 16 |
+
|
| 17 |
+
with tab1:
|
| 18 |
+
st.header("Question Summarization")
|
| 19 |
+
# Input text for summarization
|
| 20 |
+
text_to_summarize = st.text_area("Enter question to summarize:", "")
|
| 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("Question Classification")
|
| 29 |
+
# Input text for news classification
|
| 30 |
+
text_to_classify = st.text_area("Enter question title to classify:", "")
|
| 31 |
+
if st.button("Classify"):
|
| 32 |
+
# Perform question classification
|
| 33 |
+
results = classifier(text_to_classify)[0]
|
| 34 |
+
# Display the classification result
|
| 35 |
+
max_score = float('-inf')
|
| 36 |
+
max_label = ''
|
| 37 |
+
for result in results:
|
| 38 |
+
if result['score'] > max_score:
|
| 39 |
+
max_score = result['score']
|
| 40 |
+
max_label = result['label']
|
| 41 |
+
st.write("Text:", text_to_classify)
|
| 42 |
+
st.write("Category:", max_label)
|
| 43 |
+
st.write("Score:", max_score)
|