Spaces:
Sleeping
Sleeping
import streamlit as st | |
import snscrape.modules.twitter as sntwitter | |
from transformers import pipeline | |
#Load the model | |
model = pipeline(task="sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment") | |
def analyze_tweet(tweet_text): | |
results = model(tweet_text) | |
return f"Toxicity Score: {results[0]['score']}\nLabel: {results[0]['label']}" | |
def fetch_tweets(username): | |
results = [] | |
for tweet in sntwitter.TwitterUserScraper(username).get_items(): | |
tweet_text = tweet.content | |
analysis_result = analyze_tweet(tweet_text) | |
results.append(f"Tweet: {tweet_text}\n{analysis_result}\n") | |
if len(results) >= 10: | |
break | |
return "\n".join(results) | |
st.title("Toxicity Analyzer") | |
task = st.sidebar.selectbox("Select Task", ("Analyze Tweet", "Fetch Tweets")) | |
if task == "Analyze Tweet": | |
tweet_text = st.text_input("Enter the tweet text:") | |
if st.button("Analyze"): | |
if tweet_text: | |
result = analyze_tweet(tweet_text) | |
st.text(result) | |
if task == "Fetch Tweets": | |
username = st.text_input("Enter the Twitter username:") | |
if st.button("Fetch"): | |
if username: | |
results = fetch_tweets(username) | |
st.text(results) | |