Tryfonas's picture
Upload 2 files
c331741 verified
import streamlit as st
from transformers import pipeline
# Load your fine-tuned model from Hugging Face
MODEL_NAME = "Tryfonas/fine-tuned-bert-classifier-bds24" # Update with your Hugging Face model name
classifier = pipeline("text-classification", model=MODEL_NAME)
# Streamlit UI
st.title("BERT Text Classifier")
st.write("Enter text below to classify:")
# User input text
user_input = st.text_area("Input Text", "Type here...")
if st.button("Classify"):
if user_input.strip():
# Get model prediction
result = classifier(user_input)
# Extract label and confidence score
label = result[0]['label'] # Model output label
confidence = result[0]['score'] # Confidence score
# Convert model labels to "Positive" or "Negative"
if label == "LABEL_1": # Adjust based on your model's labeling
sentiment = "Positive 😊"
elif label == "LABEL_0":
sentiment = "Negative 😞"
else:
sentiment = "Unknown 🤔"
# Display results
st.subheader("Prediction:")
st.write(f"**Sentiment:** {sentiment}")
else:
st.warning("Please enter some text.")