Spaces:
Sleeping
Sleeping
add load_model and delete init
Browse files
app.py
CHANGED
@@ -10,12 +10,13 @@ from bs4 import BeautifulSoup
|
|
10 |
|
11 |
class NewsAnalytic():
|
12 |
@st.cache_resource
|
13 |
-
def
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
nltk.download("punkt")
|
18 |
print("load model berhasil!")
|
|
|
19 |
def anoted_sentence(self,content,candidate_labels):
|
20 |
sentences = nltk.sent_tokenize(content)
|
21 |
sentences = [sent for sent in sentences if "simak" not in sent.lower()]
|
@@ -46,6 +47,7 @@ class NewsAnalytic():
|
|
46 |
print("mendapatkan konten berita berhasil!")
|
47 |
return {'title': title.strip(), 'content': content.strip()}
|
48 |
def streamlit_run(self):
|
|
|
49 |
st.markdown("<h2 style='text-align: center;'>Indonesian News Analytic </h2>", unsafe_allow_html=True)
|
50 |
st.markdown("<p style='text-align: center;'>Hafizh Zaki Prasetyo Adi|[email protected]|https://www.linkedin.com/in/hafizhzpa/ </p>", unsafe_allow_html=True)
|
51 |
part=st.sidebar.radio("input_type",["content", "link"],captions = ["input news content", "input news link"])
|
@@ -66,10 +68,4 @@ class NewsAnalytic():
|
|
66 |
result_category=self.classifier(text, ["Politik","Ekonomi","Hukum dan Kriminal","Teknologi","Pendidikan","Kesehatan","Olahraga","Hiburan","Gaya Hidup","Lingkungan","Transportasi","Pariwisata"])
|
67 |
st.text(f"category: {result_category['labels'][0]}")
|
68 |
result_region=self.classifier(text, ["regional","nasional","internasional"])
|
69 |
-
st.text(f"region: {result_region['labels'][0]}")
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
if __name__=="__main__":
|
74 |
-
pipeline=NewsAnalytic()
|
75 |
-
pipeline.streamlit_run()
|
|
|
10 |
|
11 |
class NewsAnalytic():
|
12 |
@st.cache_resource
|
13 |
+
def load_model(self):
|
14 |
+
model = T5ForZeroShotClassification.from_pretrained('knowledgator/comprehend_it-multilingual-t5-base')
|
15 |
+
tokenizer = T5Tokenizer.from_pretrained('knowledgator/comprehend_it-multilingual-t5-base')
|
16 |
+
classifier = ZeroShotClassificationPipeline(model=model, tokenizer=tokenizer,ypothesis_template = '{}', encoder_decoder = True)
|
17 |
nltk.download("punkt")
|
18 |
print("load model berhasil!")
|
19 |
+
return classifier
|
20 |
def anoted_sentence(self,content,candidate_labels):
|
21 |
sentences = nltk.sent_tokenize(content)
|
22 |
sentences = [sent for sent in sentences if "simak" not in sent.lower()]
|
|
|
47 |
print("mendapatkan konten berita berhasil!")
|
48 |
return {'title': title.strip(), 'content': content.strip()}
|
49 |
def streamlit_run(self):
|
50 |
+
self.classifier=self.load_model()
|
51 |
st.markdown("<h2 style='text-align: center;'>Indonesian News Analytic </h2>", unsafe_allow_html=True)
|
52 |
st.markdown("<p style='text-align: center;'>Hafizh Zaki Prasetyo Adi|[email protected]|https://www.linkedin.com/in/hafizhzpa/ </p>", unsafe_allow_html=True)
|
53 |
part=st.sidebar.radio("input_type",["content", "link"],captions = ["input news content", "input news link"])
|
|
|
68 |
result_category=self.classifier(text, ["Politik","Ekonomi","Hukum dan Kriminal","Teknologi","Pendidikan","Kesehatan","Olahraga","Hiburan","Gaya Hidup","Lingkungan","Transportasi","Pariwisata"])
|
69 |
st.text(f"category: {result_category['labels'][0]}")
|
70 |
result_region=self.classifier(text, ["regional","nasional","internasional"])
|
71 |
+
st.text(f"region: {result_region['labels'][0]}")
|
|
|
|
|
|
|
|
|
|
|
|