Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +26 -0
- requirements.txt +60 -0
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
@st.cache
|
5 |
+
def sentiment_analysis(inp):
|
6 |
+
|
7 |
+
model_name = 'distilbert-base-uncased-finetuned-sst-2-english'
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
+
|
11 |
+
classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
12 |
+
res = classifier(inp)
|
13 |
+
return res
|
14 |
+
|
15 |
+
def main():
|
16 |
+
user_input = st.text_input("Enter text here:")
|
17 |
+
st.write("You entered:", user_input)
|
18 |
+
res = sentiment_analysis(user_input)
|
19 |
+
print(res)
|
20 |
+
sentiment = res[0]['label']
|
21 |
+
conf = res[0]['score']
|
22 |
+
st.write("Sentiment of the input: ", sentiment)
|
23 |
+
st.write("Confidence of the predicted sentiment: ", conf)
|
24 |
+
|
25 |
+
if __name__ == '__main__':
|
26 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==4.2.2
|
2 |
+
attrs==22.2.0
|
3 |
+
blinker==1.6
|
4 |
+
cachetools==5.3.0
|
5 |
+
certifi==2022.12.7
|
6 |
+
charset-normalizer==3.1.0
|
7 |
+
click==8.1.3
|
8 |
+
colorama==0.4.6
|
9 |
+
decorator==5.1.1
|
10 |
+
entrypoints==0.4
|
11 |
+
filelock==3.11.0
|
12 |
+
gitdb==4.0.10
|
13 |
+
GitPython==3.1.31
|
14 |
+
huggingface-hub==0.13.4
|
15 |
+
idna==3.4
|
16 |
+
importlib-metadata==6.2.0
|
17 |
+
Jinja2==3.1.2
|
18 |
+
jsonschema==4.17.3
|
19 |
+
markdown-it-py==2.2.0
|
20 |
+
MarkupSafe==2.1.2
|
21 |
+
mdurl==0.1.2
|
22 |
+
mpmath==1.3.0
|
23 |
+
networkx==3.1
|
24 |
+
numpy==1.24.2
|
25 |
+
packaging==23.0
|
26 |
+
pandas==1.5.3
|
27 |
+
Pillow==9.5.0
|
28 |
+
protobuf==3.20.3
|
29 |
+
pyarrow==11.0.0
|
30 |
+
pydeck==0.8.0
|
31 |
+
Pygments==2.14.0
|
32 |
+
Pympler==1.0.1
|
33 |
+
pyrsistent==0.19.3
|
34 |
+
python-dateutil==2.8.2
|
35 |
+
pytz==2023.3
|
36 |
+
pytz-deprecation-shim==0.1.0.post0
|
37 |
+
PyYAML==6.0
|
38 |
+
regex==2023.3.23
|
39 |
+
requests==2.28.2
|
40 |
+
rich==13.3.3
|
41 |
+
six==1.16.0
|
42 |
+
smmap==5.0.0
|
43 |
+
streamlit==1.21.0
|
44 |
+
sympy==1.11.1
|
45 |
+
tokenizers==0.13.3
|
46 |
+
toml==0.10.2
|
47 |
+
toolz==0.12.0
|
48 |
+
torch==2.0.0
|
49 |
+
torchaudio==2.0.1
|
50 |
+
torchvision==0.15.1
|
51 |
+
tornado==6.2
|
52 |
+
tqdm==4.65.0
|
53 |
+
transformers==4.27.4
|
54 |
+
typing_extensions==4.5.0
|
55 |
+
tzdata==2023.3
|
56 |
+
tzlocal==4.3
|
57 |
+
urllib3==1.26.15
|
58 |
+
validators==0.20.0
|
59 |
+
watchdog==3.0.0
|
60 |
+
zipp==3.15.0
|