|
import streamlit as st |
|
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer |
|
|
|
|
|
|
|
def get_model(): |
|
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased") |
|
pulled_model = AutoModelForSequenceClassification.from_pretrained( |
|
"NazmusAshrafi/large_dataset_stock_twitter_topic_Bert") |
|
return tokenizer, pulled_model |
|
|
|
|
|
tokenizer, model = get_model() |
|
|
|
|
|
classifier = pipeline("sentiment-analysis", |
|
model=model, tokenizer=tokenizer) |
|
|
|
|
|
|
|
|
|
st.title("Find the topic of a stock related tweets") |
|
st.subheader( |
|
'This model can predict 5 topics - :blue[Tesla Investment News], :green[Technology stock watchlist], :orange[Esports News], :blue[Apple Market Updates], :green[Amazon Updates] - Entering a topic related tweet will yeild the best results') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.subheader( |
|
'Examples:') |
|
st.markdown( |
|
':blue[Tesla Investment News: "Electric cars stock going to go up in future, buy now"]') |
|
st.markdown( |
|
':green[Technology stock watchlist: "Keep a look out for that stock, its really good!"]') |
|
st.markdown( |
|
':orange[Esports News: "Ninja is going to play in the next tournament, the best is back playing Fortnite."]') |
|
st.markdown( |
|
':blue[Apple Market Updates: "$AAPL released a new phone but the looks never change much. Buy anyway!"]') |
|
st.markdown( |
|
':green[Amazon Updates: "Black Fridays at Amazon, hail Jeff Bezos"]') |
|
|
|
|
|
st.subheader("", divider='rainbow') |
|
|
|
|
|
user_input = st.text_area("Enter a tweet about a stock") |
|
button = st.button("Analyze") |
|
|
|
|
|
|
|
|
|
if user_input and button: |
|
|
|
st.write("Topic Prediction: ", classifier(user_input)[0]['label']) |
|
st.write("Confidence Score: ", classifier(user_input)[0]['score']) |
|
|
|
|
|
|
|
|
|
|