Added basic structure
Browse files- app.py +14 -0
- milestone3.py +23 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
|
4 |
+
st.title("Sentiment Analysis App - beta")
|
5 |
+
st.header("This app is to analyze the sentiments behind a text. Currently it uses \
|
6 |
+
pre-trained models without fine-tuning.")
|
7 |
+
|
8 |
+
st.text_input("Enter your text:", value="Missing Sophie.Z...")
|
9 |
+
st.selectbox("Please select a model:" ("Model 1", "Model 2", "Model 3"))
|
10 |
+
|
11 |
+
if st.button("Analyze"):
|
12 |
+
st.write("You clicked a button.")
|
13 |
+
else:
|
14 |
+
st.write("Go on! Try the app!")
|
milestone3.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
|
3 |
+
import torch
|
4 |
+
import torch.nn.functional as F
|
5 |
+
|
6 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
7 |
+
|
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(["I am very happy now.", "Not happy now."])
|
13 |
+
|
14 |
+
for result in res:
|
15 |
+
print(result)
|
16 |
+
|
17 |
+
tokens = tokenizer.tokenize("I am very happy now.")
|
18 |
+
token_ids = tokenizer.convert_tokens_to_ids(tokens)
|
19 |
+
input_ids = tokenizer("I am very happy now.")
|
20 |
+
|
21 |
+
print(f'Tokens:{tokens}')
|
22 |
+
print(f'TokenIDs:{token_ids}')
|
23 |
+
print(f'InputIDs:{input_ids}')
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
transformers
|