File size: 853 Bytes
26290c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import re
import streamlit as st
import torch
st.title("film_review")

input_text = st.text_area("Enter your text")
from pages.film_review.model.model_lstm import *
from pages.film_review.model.model_logreg import *

@st.cache_resource
def get_model():
    return  torch.load("pages/film_review/model/model_lstm.pt",map_location=torch.device('cpu'))
model = get_model()
model.eval()
dec = {0:'отрицательный',1:'нейтральный',2:'положительный'}

if input_text:
    with torch.no_grad():
        ans = torch.nn.functional.softmax(model(input_text), dim=1)
    idx = torch.argmax(ans, dim=1).item()
    st.write(f'LSTM - отзыв: {dec[idx]}, уверенность: { round(ans[0][idx].item(),2)}')

    st.write(f'Logreg - отзыв: {dec[ predict_tfidf(input_text)[0]]}')




else:
    st.write("No text entered")