Spaces:
Runtime error
Runtime error
First Model Version
Browse files- README.md +3 -3
- __pycache__/news_pipeline.cpython-39.pyc +0 -0
- app.py +40 -0
- news_pipeline.py +44 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: News Analyzer
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
app_file: app.py
|
8 |
pinned: false
|
|
|
1 |
---
|
2 |
title: News Analyzer
|
3 |
+
emoji: π°
|
4 |
+
colorFrom: grey
|
5 |
+
colorTo: white
|
6 |
sdk: streamlit
|
7 |
app_file: app.py
|
8 |
pinned: false
|
__pycache__/news_pipeline.cpython-39.pyc
ADDED
Binary file (1.39 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from news_pipeline import NewsPipeline
|
4 |
+
|
5 |
+
CATEGORY_EMOJIS = {
|
6 |
+
"Automobile": "π",
|
7 |
+
"Entertainment": "πΏ",
|
8 |
+
"Politics": "βοΈ",
|
9 |
+
"Science": "π§ͺ",
|
10 |
+
"Sports": "π",
|
11 |
+
"Technology": "π»",
|
12 |
+
"World": "π",
|
13 |
+
}
|
14 |
+
FAKE_EMOJIS = {"Fake": "π»", "Real": "π"}
|
15 |
+
CLICKBAIT_EMOJIS = {"Clickbait": "π£", "Normal": "β
"}
|
16 |
+
|
17 |
+
|
18 |
+
def app():
|
19 |
+
news_pipe = NewsPipeline()
|
20 |
+
st.title("π° News Analyzer")
|
21 |
+
headline = st.text_input("Article headline:")
|
22 |
+
content = st.text_area("Article content:")
|
23 |
+
button = st.button("Analyze")
|
24 |
+
if button:
|
25 |
+
with st.spinner("Analyzing article..."):
|
26 |
+
prediction = news_pipe(headline, content)
|
27 |
+
st.success("Article successfully analyzed!")
|
28 |
+
st.markdown(
|
29 |
+
f"{CATEGORY_EMOJIS[prediction['category']]} **Category**: {prediction['category']}"
|
30 |
+
)
|
31 |
+
st.markdown(
|
32 |
+
f"{FAKE_EMOJIS[prediction['fake']]} **Fake**: {'Yes' if prediction['fake'] == 'Fake' else 'No'}"
|
33 |
+
)
|
34 |
+
st.markdown(
|
35 |
+
f"{CLICKBAIT_EMOJIS[prediction['clickbait']]} **Clickbait**: {'Yes' if prediction['clickbait'] == 'Clickbait' else 'No'}"
|
36 |
+
)
|
37 |
+
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
app()
|
news_pipeline.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict
|
2 |
+
|
3 |
+
from transformers import (
|
4 |
+
AutoModelForSequenceClassification,
|
5 |
+
AutoTokenizer,
|
6 |
+
TextClassificationPipeline,
|
7 |
+
)
|
8 |
+
|
9 |
+
|
10 |
+
class NewsPipeline:
|
11 |
+
def __init__(self) -> None:
|
12 |
+
self.category_tokenizer = AutoTokenizer.from_pretrained("elozano/news-category")
|
13 |
+
self.category_pipeline = TextClassificationPipeline(
|
14 |
+
model=AutoModelForSequenceClassification.from_pretrained(
|
15 |
+
"elozano/news-category"
|
16 |
+
),
|
17 |
+
tokenizer=self.category_tokenizer,
|
18 |
+
)
|
19 |
+
self.fake_tokenizer = AutoTokenizer.from_pretrained("elozano/news-fake")
|
20 |
+
self.fake_pipeline = TextClassificationPipeline(
|
21 |
+
model=AutoModelForSequenceClassification.from_pretrained(
|
22 |
+
"elozano/news-fake"
|
23 |
+
),
|
24 |
+
tokenizer=self.fake_tokenizer,
|
25 |
+
)
|
26 |
+
self.clickbait_pipeline = TextClassificationPipeline(
|
27 |
+
model=AutoModelForSequenceClassification.from_pretrained(
|
28 |
+
"elozano/news-clickbait"
|
29 |
+
),
|
30 |
+
tokenizer=AutoTokenizer.from_pretrained("elozano/news-clickbait"),
|
31 |
+
)
|
32 |
+
|
33 |
+
def __call__(self, headline: str, content: str) -> Dict[str, str]:
|
34 |
+
category_article_text = f" {self.category_tokenizer.sep_token} ".join(
|
35 |
+
[headline, content]
|
36 |
+
)
|
37 |
+
fake_article_text = f" {self.fake_tokenizer.sep_token} ".join(
|
38 |
+
[headline, content]
|
39 |
+
)
|
40 |
+
return {
|
41 |
+
"category": self.category_pipeline(category_article_text)[0]["label"],
|
42 |
+
"fake": self.fake_pipeline(fake_article_text)[0]["label"],
|
43 |
+
"clickbait": self.clickbait_pipeline(headline)[0]["label"],
|
44 |
+
}
|