File size: 1,600 Bytes
440b68e
 
b1dcba7
 
440b68e
 
 
 
6627e63
9fc7e76
b1dcba7
6627e63
 
440b68e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st
from newspaper import Article
from transformers import pipeline
from transformers import T5Tokenizer, T5Model, T5ForConditionalGeneration

# Load model from Hugging Face
@st.cache_resource
def load_summarizer():
    model_name = "cahya/t5-base-indonesian-summarization-cased"
    tokenizer = T5Tokenizer.from_pretrained(model_name)
    model = T5ForConditionalGeneration.from_pretrained(model_name)

    return pipeline("summarization", model=model, tokenizer=tokenizer)

summarizer = load_summarizer()

st.title("📰 Indonesian News Summarizer")
st.write("Enter a URL from an Indonesian news website (e.g. Detik.com)")

url = st.text_input("Paste the article URL here:")

if st.button("Show Article Text"):
    if url:
        try:
            article = Article(url, language='id')
            article.download()
            article.parse()
            st.subheader("Full Article:")
            st.write(article.text)
            st.session_state.article_text = article.text
        except Exception as e:
            st.error(f"Failed to fetch article: {str(e)}")
    else:
        st.warning("Please input a valid URL.")

if st.button("Summarize"):
    if "article_text" in st.session_state:
        with st.spinner("Summarizing..."):
            input_text = "ringkasan: " + st.session_state.article_text
            summary = summarizer(input_text, max_length=150, min_length=40, do_sample=False)
            st.subheader("Summary:")
            st.success(summary[0]['summary_text'])
    else:
        st.warning("No article text found. Please load the article first.")