KazSandra / app.py
lgblkb's picture
feat: add form input
a1fa344
from operator import setitem
from pathlib import Path
import streamlit as st
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
from transformers import TextClassificationPipeline
@st.cache_data()
def load_model():
model = AutoModelForSequenceClassification.from_pretrained(
"issai/rembert-sentiment-analysis-polarity-classification-kazakh")
tokenizer = AutoTokenizer.from_pretrained("issai/rembert-sentiment-analysis-polarity-classification-kazakh")
return TextClassificationPipeline(model=model, tokenizer=tokenizer)
st.title('KazSAnDRA')
static_folder = Path(__file__).parent / 'static'
assert static_folder.exists()
st.write((static_folder / 'description.txt').read_text())
st.image(str(static_folder / 'kazsandra.jpg'))
pipe = load_model()
with st.form('main_form'):
input_text = st.text_area('Input text', placeholder='Provide your text, e.g. "Осы кітап қызық сияқты".')
is_submitted = st.form_submit_button(label='Submit')
if is_submitted:
if input_text:
out = pipe(input_text)[0]
st.text("Label: {label}\nScore: {score}".format(**out))
else:
st.text("Please provide your text first.")
# reviews = ["Бұл бейнефильм маған түк ұнамады.", "Осы кітап қызық сияқты."]