Spaces:
Runtime error
Runtime error
File size: 2,984 Bytes
430933d be53401 7594b6c f4b77bb 233b979 71c5cf1 430933d c588d0a 71c5cf1 430933d 7594b6c 430933d c588d0a 430933d c588d0a 7594b6c f4b77bb 7594b6c 430933d f4b77bb e7049d4 965df62 049599a f4b77bb e7049d4 71c5cf1 430933d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import re
import tweepy
import pandas as pd
import gradio as gr
import itertools
import collections
from collections import Counter
import numpy as np
from transformers import pipeline
classifier = pipeline('sentiment-analysis')
summarizer= pipeline("summarization", max_length=10)
#hashtag_phrase ="#datascience"
#recent_tweet_count_you_want =100
def search_hashtag1(hashtag_phrase,recent_tweet_count_you_want):
#hashtag_phrase=input("Enter hashtahg")
consumer_key="30GAxNeTfZuPL5SfNhFBodmRF"
consumer_secret="C6O64nP0XjtwaAnXYL9zCcDZKEIP2iL1yVdlsNJtwLiZ5AEEBs"
access_token="1246523558563471360-WrbCqO8phqjIzx393mrfOSKvDFPmey"
access_token_secret="u7B6yX6ZyTa5ph7xkCFnbzyuD9jbuHHJNL0Y4S7mdZb1J"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
fname = '_'.join(re.findall(r"#(\w+)", hashtag_phrase))
data_frame=pd.DataFrame(columns={"timestamp"})
timestamp=[]
tweet_text=[]
user_name=[]
user_id=[]
for tweet in tweepy.Cursor(api.search_tweets, q=hashtag_phrase+' -filter:retweets',lang="en", tweet_mode='extended').items(recent_tweet_count_you_want):
timestamp1=tweet.created_at
timestamp.append(timestamp1)
#tweet_text1=tweet.full_text.replace('\n',' ').encode('utf-8')
tweet_text1=tweet.full_text
tweet_text.append(tweet_text1)
user_name1=tweet.user.screen_name.encode('utf-8')
user_name.append(user_name1)
user_id1=tweet.id
user_id.append(user_id1)
data2=pd.DataFrame(timestamp,columns={"timestamp"})
data1=pd.DataFrame(tweet_text,columns={"tweet_text"})
data3=pd.DataFrame(user_name,columns={"user_name"})
data4=pd.concat([data1,data2],axis=1)
data5=pd.concat([data4,data3],axis=1)
data7=pd.DataFrame(user_id,columns={"user_id"})
data6=pd.concat([data5,data7],axis=1)
tweet_list=data6.tweet_text.to_list()
p = [i for i in classifier(tweet_list)]
q=[p[i]['label'] for i in range(len(p))]
data10=pd.DataFrame(q,columns={"sentiment"})
data_tweet_final=pd.concat([data6,data10],axis=1)
p_summarize_label = [i for i in summarizer(tweet_list)]
q_summarize=[p_summarize_label[i]['summary_text'] for i in range(len(p_summarize_label))]
data_summarize=pd.DataFrame(q_summarize,columns={"summarized_tweets"})
data_tweet_summarize_final=pd.concat([data_tweet_final,data_summarize],axis=1)
data_tweet_summarize_final.to_csv("tweet_data2.csv")
#data6.to_csv("tweet_data1.csv")
#data6=data5.head(10)
return data_tweet_summarize_final
iface = gr.Interface(
search_hashtag1,inputs=["text","number"],
outputs="dataframe",
examples=[["#datascience",5],["#valentine's day",10],["#pushpa",15],["#budget",20],["#sharktankindia",30]],
theme="seafoam",
title='Sakil Tweetlib6 App',
description="You can extract tweets based on Hashtag.e.g. Please enter #datascience. The app extracts tweets based on the hashtag and the number of tweet count you want.")
iface.launch(inline=False) |