import streamlit as st import numpy as np import pandas as pd import re import time import os from transformers import AutoModelForSequenceClassification, AutoModel, AutoTokenizer from sklearn.metrics.pairwise import cosine_similarity from datasets import load_dataset from sentence_transformers import SentenceTransformer from Scraper import Scrap model_checkpoint = "Rifky/indobert-hoax-classification" base_model_checkpoint = "indobenchmark/indobert-base-p1" data_checkpoint = "Rifky/indonesian-hoax-news" label = {0: "valid", 1: "fake"} @st.cache(show_spinner=False, allow_output_mutation=True) def load_model(): model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint, num_labels=2) base_model = SentenceTransformer(base_model_checkpoint) tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, fast=True) data = load_dataset(data_checkpoint, split="train", download_mode='force_redownload') return model, base_model, tokenizer, data def sigmoid(x): return 1 / (1 + np.exp(-x)) with st.spinner("Loading Model..."): model, base_model, tokenizer, data = load_model() st.markdown("""
This article is {label[prediction]}.
""", unsafe_allow_html=True) else: st.markdown(f"""This article is {label[prediction]}.
""", unsafe_allow_html=True) with st.expander("Related Articles"): for i in sorted[:5]: # st.write(f"""""",unsafe_allow_html=True) st.markdown(f""" {data["url"][i].split("/")[2]}Can't scrap article from this link.
""", unsafe_allow_html=True)