Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Define
|
| 6 |
summarizer_ntg = pipeline("summarization", model="mrm8488/t5-base-finetuned-summarize-news")
|
| 7 |
-
|
| 8 |
-
# Load the tokenizer and model for classification
|
| 9 |
-
tokenizer_bb = AutoTokenizer.from_pretrained("Lauraayu/News_Classi_Model")
|
| 10 |
model_bb = AutoModelForSequenceClassification.from_pretrained("Lauraayu/News_Classi_Model")
|
| 11 |
|
| 12 |
# Streamlit application title
|
|
@@ -20,18 +17,15 @@ text = st.text_area("Enter the news article text here:")
|
|
| 20 |
if st.button("Classify"):
|
| 21 |
# Perform text summarization
|
| 22 |
summary = summarizer_ntg(text)[0]['summary_text']
|
| 23 |
-
|
| 24 |
-
# Tokenize the summarized text
|
| 25 |
-
inputs = tokenizer_bb(summary, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
| 26 |
-
|
| 27 |
# Move inputs and model to the same device (GPU or CPU)
|
| 28 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 29 |
-
|
| 30 |
model_bb.to(device)
|
| 31 |
|
| 32 |
# Perform text classification
|
| 33 |
with torch.no_grad():
|
| 34 |
-
outputs = model_bb(**
|
| 35 |
|
| 36 |
# Get the predicted label
|
| 37 |
predicted_label_id = torch.argmax(outputs.logits, dim=-1).item()
|
|
|
|
| 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
|
|
|
|
| 17 |
if st.button("Classify"):
|
| 18 |
# Perform text summarization
|
| 19 |
summary = summarizer_ntg(text)[0]['summary_text']
|
| 20 |
+
|
|
|
|
|
|
|
|
|
|
| 21 |
# Move inputs and model to the same device (GPU or CPU)
|
| 22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
+
summary = {k: v.to(device) for k, v in inputs.items()}
|
| 24 |
model_bb.to(device)
|
| 25 |
|
| 26 |
# Perform text classification
|
| 27 |
with torch.no_grad():
|
| 28 |
+
outputs = model_bb(**summary)
|
| 29 |
|
| 30 |
# Get the predicted label
|
| 31 |
predicted_label_id = torch.argmax(outputs.logits, dim=-1).item()
|