Anna-UoC commited on
Commit
517802f
·
1 Parent(s): 6c8a85e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import transformers
3
+ from transformers import AutoTokenizer
4
+ from transformers import AutoModelForSequenceClassification
5
+ from transformers import pipeline
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
8
+
9
+ model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
10
+ st.title("Text Classification with BERT")
11
+
12
+ text = st.text_input("Enter some text")
13
+ if text:
14
+ encoded_text = tokenizer.encode_plus(text, max_length=128, padding="max_length", truncation=True, return_tensors="pt")
15
+ logits = model(encoded_text["input_ids"], attention_mask=encoded_text["attention_mask"]).logits
16
+ pred = logits.argmax().item()
17
+ st.write("Prediction:", pred)
18
+
19
+ #st.text_input('First name')
20
+
21
+ #classifier = pipeline("text-classification", model=model)
22
+ #classifier('st.text_input')
23
+
24
+ #st.text('Fixed width text')
25
+
26
+ #x = st.slider('Select a value')
27
+ #st.write(x, 'squared is', x * x)