Spaces:
Runtime error
Runtime error
Commit ·
2391bdc
1
Parent(s): 42fc5a0
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
def sentiment_analysis(text, model_name):
|
| 6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
classifier = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
|
| 10 |
+
result = classifier(text)
|
| 11 |
+
|
| 12 |
+
return result[0]['label']
|
| 13 |
+
|
| 14 |
+
def main():
|
| 15 |
+
st.title("Sentiment Analysis App")
|
| 16 |
+
text = st.text_input("Enter text:")
|
| 17 |
+
model_name = st.selectbox("Select a pretrained model", ["bert-base-uncased", "distilbert-base-uncased", "roberta-base"])
|
| 18 |
+
|
| 19 |
+
if st.button("Analyze"):
|
| 20 |
+
with st.spinner('Analyzing...'):
|
| 21 |
+
sentiment = sentiment_analysis(text, model_name)
|
| 22 |
+
st.write("Sentiment:", sentiment)
|
| 23 |
+
|
| 24 |
+
if __name__ == '__main__':
|
| 25 |
+
main()
|
| 26 |
+
|