lgblkb commited on
Commit
a1fa344
1 Parent(s): 242bc2f

feat: add form input

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from pathlib import Path
2
 
3
  import streamlit as st
@@ -8,7 +9,7 @@ from transformers import TextClassificationPipeline
8
 
9
 
10
  @st.cache_data()
11
- def get_pipe():
12
  model = AutoModelForSequenceClassification.from_pretrained(
13
  "issai/rembert-sentiment-analysis-polarity-classification-kazakh")
14
  tokenizer = AutoTokenizer.from_pretrained("issai/rembert-sentiment-analysis-polarity-classification-kazakh")
@@ -22,10 +23,16 @@ assert static_folder.exists()
22
  st.write((static_folder / 'description.txt').read_text())
23
  st.image(str(static_folder / 'kazsandra.jpg'))
24
 
25
- input_text = st.text_area('Input text', placeholder='Provide your text', value='Осы кітап қызық сияқты.')
 
 
 
 
 
 
 
 
 
 
 
26
  # reviews = ["Бұл бейнефильм маған түк ұнамады.", "Осы кітап қызық сияқты."]
27
- pipe = get_pipe()
28
- # for review in reviews:
29
- if input_text:
30
- out = pipe(input_text)[0]
31
- st.text("Label: {label}\nScore: {score}".format(**out))
 
1
+ from operator import setitem
2
  from pathlib import Path
3
 
4
  import streamlit as st
 
9
 
10
 
11
  @st.cache_data()
12
+ def load_model():
13
  model = AutoModelForSequenceClassification.from_pretrained(
14
  "issai/rembert-sentiment-analysis-polarity-classification-kazakh")
15
  tokenizer = AutoTokenizer.from_pretrained("issai/rembert-sentiment-analysis-polarity-classification-kazakh")
 
23
  st.write((static_folder / 'description.txt').read_text())
24
  st.image(str(static_folder / 'kazsandra.jpg'))
25
 
26
+ pipe = load_model()
27
+
28
+ with st.form('main_form'):
29
+ input_text = st.text_area('Input text', placeholder='Provide your text, e.g. "Осы кітап қызық сияқты".')
30
+ is_submitted = st.form_submit_button(label='Submit')
31
+ if is_submitted:
32
+ if input_text:
33
+ out = pipe(input_text)[0]
34
+ st.text("Label: {label}\nScore: {score}".format(**out))
35
+ else:
36
+ st.text("Please provide your text first.")
37
+
38
  # reviews = ["Бұл бейнефильм маған түк ұнамады.", "Осы кітап қызық сияқты."]