Tryfonas commited on
Commit
c331741
·
verified ·
1 Parent(s): ce03210

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load your fine-tuned model from Hugging Face
5
+ MODEL_NAME = "Tryfonas/fine-tuned-bert-classifier-bds24" # Update with your Hugging Face model name
6
+ classifier = pipeline("text-classification", model=MODEL_NAME)
7
+
8
+ # Streamlit UI
9
+ st.title("BERT Text Classifier")
10
+ st.write("Enter text below to classify:")
11
+
12
+ # User input text
13
+ user_input = st.text_area("Input Text", "Type here...")
14
+
15
+ if st.button("Classify"):
16
+ if user_input.strip():
17
+ # Get model prediction
18
+ result = classifier(user_input)
19
+
20
+ # Extract label and confidence score
21
+ label = result[0]['label'] # Model output label
22
+ confidence = result[0]['score'] # Confidence score
23
+
24
+ # Convert model labels to "Positive" or "Negative"
25
+ if label == "LABEL_1": # Adjust based on your model's labeling
26
+ sentiment = "Positive 😊"
27
+ elif label == "LABEL_0":
28
+ sentiment = "Negative 😞"
29
+ else:
30
+ sentiment = "Unknown 🤔"
31
+
32
+ # Display results
33
+ st.subheader("Prediction:")
34
+ st.write(f"**Sentiment:** {sentiment}")
35
+ else:
36
+ st.warning("Please enter some text.")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ transformers