This is a Streamlit app for sentiment analysis that uses XLM RoBERTa model on Hugging Face. The program scrapes twitter for tweets that are about a certain company. The tweets are then fed into a model for sentiment analysis.
- You can find our CUSTOM MODEL in this repo here
Below is a video demo of the app.
Preview.mp4
To be able to use this app, please follow the instructions below. First, you need to install requirements using the following command.
pip install -r requirements.txt
After that, you need to download this model from Hugging Face.
from transformers import pipeline
import tokenizers
# this will download 2 GB
nlp = pipeline("sentiment-analysis", model='akhooli/xlm-r-large-arabic-sent')
# Save it in the same app folder
# .save_pretrained(path)
# 'XLM-R-L-ARABIC-SENT' is the folder name of the model
nlp.save_pretrained('XLM-R-L-ARABIC-SENT')
This will produce a folder that has the model. Please include the folder in the same directory as 'app.py'.
In case you want to replace this model with another, you want to download your model and edit the setup_model()
function. Implementation is shown below.
def setup_model():
"""
Setup Model
"""
#*************************************************
# -==EDIT THE LINE BELOW WITH YOUR OWN MODEL==-
#*************************************************
nlp = pipeline("sentiment-analysis", model='XLM-R-L-ARABIC-SENT')
return nlp
Now to run the app, just simply run the command below in a terminal.
streamlit run app.py
Below you can find all the settings you can tweak that are related to your query.
If the program was unable to find enough tweets for a given query then the message below will show.
WordCloud is not available for Arabic due to the library not being compatable with Arabic.
This Streamlit app was developed as part of my Data Scientist intern position at Banque Misr.