| | import streamlit as st |
| | from transformers import pipeline |
| |
|
| | def main(): |
| | sentiment_pipeline = pipeline(model="frankai98/Yelp_Bert") |
| |
|
| | st.title("Sentiment Analysis with HuggingFace Spaces") |
| | st.write("Enter a sentence to analyze its sentiment:") |
| |
|
| | user_input = st.text_input("") |
| | if user_input: |
| | result = sentiment_pipeline(user_input) |
| | sentiment_label = result[0]["label"] |
| | confidence = result[0]["score"] |
| | |
| | |
| | if sentiment_label.startswith("LABEL_"): |
| | try: |
| | |
| | label_num = int(sentiment_label.split("_")[1]) |
| | |
| | stars = label_num + 1 |
| | st.write(f"Sentiment: {stars} stars") |
| | except (ValueError, IndexError): |
| | |
| | st.write(f"Sentiment: {sentiment_label}") |
| | else: |
| | |
| | st.write(f"Sentiment: {sentiment_label}") |
| | |
| | st.write(f"Confidence: {confidence:.2f}") |
| |
|
| | if __name__ == "__main__": |
| | main() |