Lauraayu commited on
Commit
0f264ab
·
verified ·
1 Parent(s): 669f80a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -26
app.py CHANGED
@@ -1,32 +1,26 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- import torch
4
 
5
- # Define pipelines
6
- summarizer_ntg = pipeline("summarization", model="mrm8488/t5-base-finetuned-summarize-news")
7
- model_bb = AutoModelForSequenceClassification.from_pretrained("Lauraayu/News_Classi_Model")
8
-
9
- # Streamlit application title
10
- st.title("News Article Summarizer and Classifier")
11
- st.write("Enter a news article text to get its summary and category.")
12
-
13
- # Text input for user to enter the news article text
14
- text = st.text_area("Enter the news article text here:")
15
-
16
- # Perform summarization and classification when the user clicks the "Classify" button
17
- if st.button("Classify"):
18
- # Perform text summarization
19
- summary = summarizer_ntg(text)[0]['summary_text']
20
 
21
- # Perform text classification
22
- with torch.no_grad():
23
- outputs = model_bb(**summary)
24
 
25
- # Get the predicted label
26
- predicted_label_id = torch.argmax(outputs.logits, dim=-1).item()
27
- label_mapping = model_bb.config.id2label
28
- predicted_label = label_mapping[predicted_label_id]
29
 
30
- # Display the summary and classification result
31
- st.write("Summary:", summary)
32
- st.write("Category:", predicted_label)
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
 
3
 
4
+ def main():
5
+ # Define pipelines
6
+ summarizer_ntg = pipeline(model="mrm8488/t5-base-finetuned-summarize-news")
7
+ model = pipeline(model="Lauraayu/News_Classi_Model")
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ # Streamlit application title
10
+ st.title("News Article Classifier")
11
+ st.write("Enter a news article text to get its category:")
12
 
13
+ # Text input for user to enter the news article text
14
+ text = st.text_area("Enter the news article text here:")
 
 
15
 
16
+ # Perform summarization and classification when the user clicks the "Classify" button
17
+ if st.button("Classify"):
18
+ # Perform text summarization
19
+ summary = summarizer_ntg(text)[0]
20
+
21
+ # Perform classification
22
+ output = model(summary)
23
+ category = output[0]["label"]
24
+
25
+ # Display the summary and classification result
26
+ st.write("Category:", category)