File size: 983 Bytes
1b05faa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pickle
from sentence_transformers import SentenceTransformer
import pandas as pd
import numpy as np


lr_model_loaded = pickle.load(open('./models/lr_model.pkl', 'rb'))
scaler_loaded = pickle.load(open('./models/scaler.pkl', 'rb'))
stmodel = SentenceTransformer("all-MiniLM-L6-v2")


def predict(context):
    r = stmodel.encode(context)
    y_pred = scaler_loaded.transform([r])
    #print(y_pred)
    result = lr_model_loaded.predict(y_pred)
    return 'บทวิเคราะห์' if result[0] == 1 else 'ไม่ใช่บทวิเคราะห์'

context = st.text_area('ใส่ข่าววิเคราะห์ที่นี่',height=300)
if context:
  r = predict(context)
  if r == "บทวิเคราะห์":
    st.write("เนื้อหานี้เป็นบทวิเคราะห์")
  else:
    st.write("เนื้อหานี้ไม่ใช่บทวิเคราะห์")