Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Sentiment Analysis App")
|
| 6 |
+
st.sidebar.title("Sentiment Analysis App")
|
| 7 |
+
st.sidebar.write("Choose a pre-trained model for sentiment analysis")
|
| 8 |
+
model_name = st.sidebar.selectbox("Select Model", ["bert-base-uncased", "distilbert-base-uncased", "roberta-base"])
|
| 9 |
+
text_input = st.text_input("Enter text for sentiment analysis")
|
| 10 |
+
|
| 11 |
+
if st.button("Analyze"):
|
| 12 |
+
if text_input:
|
| 13 |
+
sentiment_classifier = pipeline("sentiment-analysis", model=model_name)
|
| 14 |
+
result = sentiment_classifier(text_input)[0]
|
| 15 |
+
st.write(f"Sentiment: {result['label']}")
|
| 16 |
+
st.write(f"Score: {round(result['score'], 4)}")
|
| 17 |
+
else:
|
| 18 |
+
st.warning("Please enter some text for sentiment analysis")
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
main()
|
| 22 |
+
|
| 23 |
+
import streamlit as st
|
| 24 |
+
import pandas as pd
|
| 25 |
+
from transformers import pipeline
|
| 26 |
+
|
| 27 |
+
def main():
|
| 28 |
+
st.set_page_config(page_title="Sentiment Analysis App")
|
| 29 |
+
st.sidebar.title("Sentiment Analysis App")
|
| 30 |
+
st.sidebar.write("Choose a pre-trained model for sentiment analysis")
|
| 31 |
+
model_name = st.sidebar.selectbox("Select Model", ["bert-base-uncased", "distilbert-base-uncased", "roberta-base"])
|
| 32 |
+
text_input = st.text_input("Enter text for sentiment analysis")
|
| 33 |
+
|
| 34 |
+
if st.button("Analyze"):
|
| 35 |
+
if text_input:
|
| 36 |
+
sentiment_classifier = pipeline("sentiment-analysis", model=model_name)
|
| 37 |
+
result = sentiment_classifier(text_input)[0]
|
| 38 |
+
st.write(f"Sentiment: {result['label']}")
|
| 39 |
+
st.write(f"Score: {round(result['score'], 4)}")
|
| 40 |
+
else:
|
| 41 |
+
st.warning("Please enter some text for sentiment analysis")
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
main()
|