Akhil Koduri commited on
Commit
d791bac
·
verified ·
1 Parent(s): 4565014

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -5,8 +5,16 @@ from transformers import pipeline
5
  model_name = "google-bert/bert-base-uncased"
6
  pipe = pipeline("text-classification", model=model_name)
7
 
 
 
 
 
 
 
8
  # Streamlit app
9
- st.title("BERT Text Classification")
 
 
10
 
11
  input_text = st.text_area("Enter text to classify")
12
 
@@ -15,7 +23,11 @@ if st.button("Classify"):
15
  # Perform classification
16
  result = pipe(input_text)
17
 
18
- st.write(f"Predicted Class: {result[0]['label']}")
19
- st.write(f"Confidence: {result[0]['score']:.4f}")
 
 
 
 
20
  else:
21
  st.write("Please enter some text to classify.")
 
5
  model_name = "google-bert/bert-base-uncased"
6
  pipe = pipeline("text-classification", model=model_name)
7
 
8
+ # Custom labels for your classification task
9
+ labels = {
10
+ "LABEL_0": "Negative",
11
+ "LABEL_1": "Positive"
12
+ }
13
+
14
  # Streamlit app
15
+ st.title("Text Classification")
16
+
17
+ st.write("This app uses a pre-trained BERT model to classify text into positive or negative sentiment.")
18
 
19
  input_text = st.text_area("Enter text to classify")
20
 
 
23
  # Perform classification
24
  result = pipe(input_text)
25
 
26
+ # Extract label and score
27
+ label = labels.get(result[0]['label'], result[0]['label'])
28
+ score = result[0]['score']
29
+
30
+ st.write(f"**Predicted Class:** {label}")
31
+ st.write(f"**Confidence:** {score:.4f}")
32
  else:
33
  st.write("Please enter some text to classify.")