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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from statsmodels.tsa.arima.model import ARIMA
|
| 3 |
+
from statsmodels.tsa.forecasting.stl import STLForecast
|
| 4 |
+
from statsmodels.tsa.seasonal import STL
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import plotly.express as px
|
| 7 |
+
import json
|
| 8 |
+
import pickle
|
| 9 |
+
import numpy as np
|
| 10 |
+
import plotly.graph_objects as go
|
| 11 |
+
from plotly.subplots import make_subplots
|
| 12 |
+
|
| 13 |
+
newsAgenciesDic={'bbc.json':'BBC Persian',
|
| 14 |
+
'fars.json':'Fars News Agency',
|
| 15 |
+
'irna.json':'IRNA News Agency',
|
| 16 |
+
'iranint.json':'Iran International',
|
| 17 |
+
'voa.json':'VOA News',
|
| 18 |
+
'khabar.json':'Khabar Online',
|
| 19 |
+
'tabnak.json':'Tabnak News Agency',
|
| 20 |
+
'mamlekat.json':'Mamlekate Telegram Channel',
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
tags=["Politics Diplomacy Government",'Sanctions', "Religion Islam",'Women girl female',
|
| 24 |
+
"Economy Finance Business",'Violance Demonstration Death Crime', "Sports Game",
|
| 25 |
+
"Entertainment Art Fashion", "Health Healthcare Medicine", "Technology Science Education",
|
| 26 |
+
"Environment Weather Agriculture Nature", "Military Defence War Attack", "Media Journalism Socialnetwork",
|
| 27 |
+
"Movies Music Books Literature", "Advertising Marketing"]
|
| 28 |
+
emotions = [ "Joy", "Love", "Gratitude", "Excitement", "Calmness",
|
| 29 |
+
"Nostalgia", "Sadness", "Anger", "Fear", "Disgust", "Frustration",
|
| 30 |
+
"Guilt", "Shame", "Surprise"]
|
| 31 |
+
sentiments=['positive sentiment','negative sentiment']
|
| 32 |
+
|
| 33 |
+
#s_tags_en=['social','economic','international','political','scientific','cultural','sport','medical']
|
| 34 |
+
s_tags=['اجتماعی','اقتصادی','بین الملل','سیاسی','علمی فناوری','فرهنگی هنری','ورزشی','پزشکی']
|
| 35 |
+
s_sentiments=['Negative','Neutral','Positive']
|
| 36 |
+
s_emotions=['furious', 'angry', 'neutral', 'happy', 'delighted']
|
| 37 |
+
|
| 38 |
+
def news_signal(news_id_1,topics,allTopics,dfselector,period,rangeYear1,rangeYear2,chart_type,normalize,modelSel,modelType):
|
| 39 |
+
#load df from disk
|
| 40 |
+
dfselector=str(4-dfselector)
|
| 41 |
+
#get key for news_id_1 from newsAgenciesDic
|
| 42 |
+
title=news_id_1
|
| 43 |
+
news_id_1=list(newsAgenciesDic.keys())[list(newsAgenciesDic.values()).index(news_id_1)]
|
| 44 |
+
model_sel='u_'
|
| 45 |
+
if modelSel=='Supervised':
|
| 46 |
+
model_sel=''
|
| 47 |
+
model_type='t_'
|
| 48 |
+
if modelType=='Sentiment':
|
| 49 |
+
model_type='s_'
|
| 50 |
+
if modelType=='Emotion':
|
| 51 |
+
model_type='e_'
|
| 52 |
+
|
| 53 |
+
df=pd.read_csv('dfs\\'+model_sel+'scores_'+model_type+news_id_1+'.csv',index_col=0)
|
| 54 |
+
|
| 55 |
+
df.index=pd.to_datetime(df.index)
|
| 56 |
+
#filter df index by year
|
| 57 |
+
df=df.loc[str(rangeYear1):str(rangeYear2)]
|
| 58 |
+
|
| 59 |
+
#group by month
|
| 60 |
+
if period=='Week':
|
| 61 |
+
period='W'
|
| 62 |
+
elif period=='Month':
|
| 63 |
+
period='M'
|
| 64 |
+
else:
|
| 65 |
+
period='Y'
|
| 66 |
+
|
| 67 |
+
df_grouped=df.resample(period).sum()
|
| 68 |
+
|
| 69 |
+
if normalize=='True':
|
| 70 |
+
#convert each group into percentage
|
| 71 |
+
#df_grouped=df_grouped.div(df_grouped.sum(axis=1), axis=0)
|
| 72 |
+
df_grouped=df.resample(period).mean()
|
| 73 |
+
else:
|
| 74 |
+
df_grouped=df.resample(period).sum()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# print(topics)
|
| 78 |
+
# fig = px.line(df_m[[topics]])
|
| 79 |
+
if len(topics)==0:
|
| 80 |
+
return px.line()
|
| 81 |
+
if allTopics=='False':
|
| 82 |
+
df_grouped=df_grouped[topics]
|
| 83 |
+
#topics=[t.lower() for t in tags]
|
| 84 |
+
|
| 85 |
+
if chart_type=='Line':
|
| 86 |
+
fig=px.line(df_grouped)
|
| 87 |
+
|
| 88 |
+
else:
|
| 89 |
+
#bar chart
|
| 90 |
+
fig=px.bar(df_grouped)
|
| 91 |
+
|
| 92 |
+
#fig.add_trace(px.bar(df_grouped),row=1,col=1)
|
| 93 |
+
fig.update_layout(title=title, xaxis_title="Date", yaxis_title="News Signal",height=1000)
|
| 94 |
+
return fig
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def news_signal_predict(news_id_2,topics_2,dfselector_2,period_2,rangeYear1_2,rangeYear2_2,normalize_2,predMode):
|
| 99 |
+
dfselector_2=str(4-dfselector_2)
|
| 100 |
+
news_id_2=list(newsAgenciesDic.keys())[list(newsAgenciesDic.values()).index(news_id_2)]
|
| 101 |
+
# df=pd.read_csv('df'+dfselector_2+'_'+news_id_2+'.csv',index_col=0)
|
| 102 |
+
model_sel='u_'
|
| 103 |
+
|
| 104 |
+
model_type='t_'
|
| 105 |
+
df=pd.read_csv('dfs\\'+model_sel+'scores_'+model_type+news_id_2+'.csv',index_col=0)
|
| 106 |
+
|
| 107 |
+
df.index=pd.to_datetime(df.index)
|
| 108 |
+
df=df.loc[str(rangeYear1_2):str(rangeYear2_2)]
|
| 109 |
+
|
| 110 |
+
pred_len=10
|
| 111 |
+
if period_2=='Week':
|
| 112 |
+
period_2='W'
|
| 113 |
+
pred_len=pred_len*7
|
| 114 |
+
elif period_2=='Month':
|
| 115 |
+
period_2='M'
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
df_grouped=df.resample(period_2).sum()
|
| 120 |
+
|
| 121 |
+
if normalize_2=='True':
|
| 122 |
+
df_grouped=df_grouped.div(df_grouped.sum(axis=1), axis=0)
|
| 123 |
+
|
| 124 |
+
if predMode=='STL':
|
| 125 |
+
stl = STL(df_grouped[topics_2], seasonal=13, period=7, robust=True)
|
| 126 |
+
res = stl.fit()
|
| 127 |
+
fig = make_subplots(rows=4, cols=1,shared_xaxes=True)
|
| 128 |
+
fig.add_trace(go.Scatter(x=res.observed.index, y=res.observed.values, mode='lines', name='Original'),row=1, col=1)
|
| 129 |
+
fig.add_trace(go.Scatter(x=res.trend.index, y=res.trend.values, mode='lines', name='Trend'),row=2, col=1)
|
| 130 |
+
fig.add_trace(go.Scatter(x=res.seasonal.index, y=res.seasonal.values, mode='lines', name='Seasonal'),row=3, col=1)
|
| 131 |
+
fig.add_trace(go.Scatter(x=res.resid.index, y=res.resid.values, mode='lines', name='Residual'),row=4, col=1)
|
| 132 |
+
#hide plotly tools
|
| 133 |
+
fig.update_layout(showlegend=False)
|
| 134 |
+
#add title to each subplot
|
| 135 |
+
fig.update_yaxes(row=1,title_text="Original")
|
| 136 |
+
fig.update_yaxes(row=2,title_text="Trend")
|
| 137 |
+
fig.update_yaxes(row=3,title_text="Seasonal")
|
| 138 |
+
fig.update_yaxes(row=4,title_text="Residual")
|
| 139 |
+
fig.update_layout(title='STL Forecast'+topics_2+' for '+news_id_2,height=800)
|
| 140 |
+
return fig
|
| 141 |
+
|
| 142 |
+
elif predMode=='ARIMA':
|
| 143 |
+
stlf = STLForecast(df_grouped[topics_2], ARIMA, model_kwargs=dict(order=(1, 1, 0), trend="t") ,robust=True)
|
| 144 |
+
res = stlf.fit()
|
| 145 |
+
forcast=res.forecast(pred_len)
|
| 146 |
+
#use plotly
|
| 147 |
+
fig = px.line(x=df_grouped[topics_2].index,y=df_grouped[topics_2].values)
|
| 148 |
+
fig.add_scatter(x=forcast.index,y=forcast.values)
|
| 149 |
+
fig.update_layout(title='ARIMA Forecast'+topics_2+' for '+news_id_2)
|
| 150 |
+
return fig
|
| 151 |
+
elif predMode.find('CTG')!=-1:
|
| 152 |
+
|
| 153 |
+
allDFs=[]
|
| 154 |
+
for newsID in list(newsAgenciesDic.keys()):
|
| 155 |
+
df=pd.read_csv('dfs\\'+model_sel+'scores_'+model_type+newsID+'.csv',index_col=0)
|
| 156 |
+
|
| 157 |
+
#df=pd.read_csv('df'+dfselector_2+'_'+newsID+'.csv',index_col=0)
|
| 158 |
+
df.index=pd.to_datetime(df.index)
|
| 159 |
+
df=df.loc[str(rangeYear1_2):str(rangeYear2_2)]
|
| 160 |
+
|
| 161 |
+
#if normalize_2=='True':
|
| 162 |
+
# df_grouped=df_grouped.div(df_grouped.sum(axis=1), axis=0)
|
| 163 |
+
if normalize_2=='True':
|
| 164 |
+
df_grouped=df.resample('M').mean()
|
| 165 |
+
else:
|
| 166 |
+
df_grouped=df.resample('M').sum()
|
| 167 |
+
|
| 168 |
+
#print(newsID,df_grouped[topics_2].head())
|
| 169 |
+
|
| 170 |
+
allDFs.append(df_grouped[topics_2])
|
| 171 |
+
#merge all dataframes on index
|
| 172 |
+
dfs=pd.concat(allDFs,axis=1)
|
| 173 |
+
#rename columns
|
| 174 |
+
dfs.columns=newsAgenciesDic.values()
|
| 175 |
+
#remove the last month data
|
| 176 |
+
dfs=dfs.iloc[:-1]
|
| 177 |
+
#remove rows with missing values
|
| 178 |
+
dfs.fillna(0,inplace=True)
|
| 179 |
+
#print('ALL',len(allDFs),dfs.head())
|
| 180 |
+
|
| 181 |
+
if predMode=='CTG1':
|
| 182 |
+
#create a subplot in each row
|
| 183 |
+
fig=make_subplots(rows=len(dfs.columns),cols=1,shared_xaxes=True,subplot_titles=list(newsAgenciesDic.values()))
|
| 184 |
+
|
| 185 |
+
for i in range(len(dfs.columns)):
|
| 186 |
+
fig.add_trace(go.Scatter(x=dfs.index,y=dfs.iloc[:,i],mode='lines',name=list(newsAgenciesDic.values())[i]),row=i+1,col=1)
|
| 187 |
+
#hide plotly tools
|
| 188 |
+
fig.update_layout(showlegend=False,height=1200,title='NEWS Signal Comparison for Topic: '+topics_2)
|
| 189 |
+
else:
|
| 190 |
+
|
| 191 |
+
#return plotly figure
|
| 192 |
+
fig=px.line(dfs)
|
| 193 |
+
fig.update_layout(title='NEWS Signal Comparison for Topic: '+topics_2)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
return fig#dfs.plot()
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
#plt.plot(df_grouped[topics_2])
|
| 202 |
+
#plt.plot(forcast)
|
| 203 |
+
#increase size of plot
|
| 204 |
+
#plt.rcParams["figure.figsize"] = (20,10)
|
| 205 |
+
|
| 206 |
+
def fn_model_sel(modelSel,modelType):
|
| 207 |
+
print(modelSel,modelType)
|
| 208 |
+
if modelSel=='Self-Supervised':
|
| 209 |
+
if modelType=='Tag':
|
| 210 |
+
return topics.update(choices=tags,value=tags[0])
|
| 211 |
+
if modelType=='Sentiment':
|
| 212 |
+
return topics.update(choices=sentiments,value=sentiments[0])
|
| 213 |
+
if modelType=='Emotion':
|
| 214 |
+
return topics.update(choices=emotions,value=emotions[0])
|
| 215 |
+
else:
|
| 216 |
+
if modelType=='Tag':
|
| 217 |
+
return topics.update(choices=s_tags,value=s_tags[0])
|
| 218 |
+
if modelType=='Sentiment':
|
| 219 |
+
return topics.update(choices=s_sentiments,value=s_sentiments[0])
|
| 220 |
+
if modelType=='Emotion':
|
| 221 |
+
return topics.update(choices=s_emotions,value=s_emotions[0])
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def news_signal_correlation(news_id_3,news_id_4,rangeYear1_3,rangeYear2_3,modelType,modelSel):
|
| 226 |
+
model_sel='u_'
|
| 227 |
+
if modelSel=='Supervised':
|
| 228 |
+
model_sel=''
|
| 229 |
+
model_type='t_'
|
| 230 |
+
if modelType=='Sentiment':
|
| 231 |
+
model_type='s_'
|
| 232 |
+
if modelType=='Emotion':
|
| 233 |
+
model_type='e_'
|
| 234 |
+
|
| 235 |
+
news_id_3=list(newsAgenciesDic.keys())[list(newsAgenciesDic.values()).index(news_id_3)]
|
| 236 |
+
df1=pd.read_csv('dfs\\'+model_sel+'scores_'+model_type+news_id_3+'.csv',index_col=0)
|
| 237 |
+
df1.index=pd.to_datetime(df1.index)
|
| 238 |
+
df1=df1.loc[str(rangeYear1_3):str(rangeYear2_3)]
|
| 239 |
+
|
| 240 |
+
if news_id_4=='none':
|
| 241 |
+
fig = go.Figure()
|
| 242 |
+
fig.add_trace(go.Heatmap(z=df1.corr(), x=df1.columns, y=df1.columns))
|
| 243 |
+
fig.update_layout(title_text=modelSel+' '+modelType+' '+"Correlation Heatmap "+newsAgenciesDic[news_id_3],height=1000)
|
| 244 |
+
return fig
|
| 245 |
+
else:
|
| 246 |
+
|
| 247 |
+
news_id_4=list(newsAgenciesDic.keys())[list(newsAgenciesDic.values()).index(news_id_4)]
|
| 248 |
+
df2=pd.read_csv('dfs\\'+model_sel+'scores_'+model_type+news_id_4+'.csv',index_col=0)
|
| 249 |
+
df2.index=pd.to_datetime(df2.index)
|
| 250 |
+
df2=df2.loc[str(rangeYear1_3):str(rangeYear2_3)]
|
| 251 |
+
|
| 252 |
+
corr=df1.corrwith(df2)
|
| 253 |
+
#plotly bar plot corr
|
| 254 |
+
fig=px.bar(corr)
|
| 255 |
+
fig.update_layout(showlegend=False,title_text=modelSel+' '+modelType+' ' +"Correlation Chart between "+
|
| 256 |
+
newsAgenciesDic[news_id_3]+' and '+ newsAgenciesDic[news_id_4],height=1000)
|
| 257 |
+
return fig
|
| 258 |
+
|
| 259 |
+
with gr.Blocks(title='QNEWS') as demo:
|
| 260 |
+
gr.Markdown('# NEWS SIGNAL ANALYSIS')
|
| 261 |
+
|
| 262 |
+
with gr.Tab('Signal Analysis'):
|
| 263 |
+
with gr.Row(variant='panel'):
|
| 264 |
+
with gr.Column():
|
| 265 |
+
news_id_1 = gr.Dropdown(list(newsAgenciesDic.values()),label='Select News Agency',value=list(newsAgenciesDic.values())[0])
|
| 266 |
+
modelType = gr.Radio(['Tag','Sentiment','Emotion'],label='Model Type',value='Tag')
|
| 267 |
+
|
| 268 |
+
modelSel = gr.Radio(['Self-Supervised','Supervised'],label='Model Selection',value='Self-Supervised')
|
| 269 |
+
topics = gr.CheckboxGroup(tags,label='Select Topic\'s Signal',value=tags[0],multiselect=True)
|
| 270 |
+
allTopics = gr.Radio(['True','False'],label='Select All Topics',value='False')
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
with gr.Column(scale=0.5):
|
| 274 |
+
period = gr.Radio(['Week','Month','Year'],label='Select Grouping Period',value='Month')
|
| 275 |
+
chart_type = gr.Radio(['Line','Bar'],label='Select Chart Type',value='Line')
|
| 276 |
+
normalize = gr.Radio(['True','False'],label='Signal Normalization',value='False')
|
| 277 |
+
dfselector = gr.Slider(minimum=1,maximum=3,step=1,value=2,label='Select Signal Sensitivity from 1 to 3',visible=False)
|
| 278 |
+
|
| 279 |
+
rangeYear1 = gr.Slider(minimum=2015,maximum=2022,step=1,value=2015,label='From Year')
|
| 280 |
+
rangeYear2 = gr.Slider(minimum=2016,maximum=2023,step=1,value=2023,label='To Year')
|
| 281 |
+
# btn_predict = gr.Radio(['a','b','c'],label='Signal Mode',value='a')
|
| 282 |
+
bt1=gr.Button()
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
inputs=[news_id_1,topics,allTopics,dfselector,period,rangeYear1,rangeYear2,chart_type,normalize,modelSel,modelType]
|
| 286 |
+
|
| 287 |
+
with gr.Row():
|
| 288 |
+
output = gr.Plot()
|
| 289 |
+
|
| 290 |
+
modelType.change(fn_model_sel,[modelSel,modelType],topics)
|
| 291 |
+
modelSel.change(fn_model_sel,[modelSel,modelType],topics)
|
| 292 |
+
normalize.change(news_signal,inputs, output)
|
| 293 |
+
chart_type.change(news_signal,inputs, output)
|
| 294 |
+
rangeYear2.change(news_signal,inputs, output)
|
| 295 |
+
rangeYear1.change(news_signal,inputs, output)
|
| 296 |
+
period.change(news_signal,inputs, output)
|
| 297 |
+
dfselector.change(news_signal,inputs, output)
|
| 298 |
+
allTopics.change(news_signal,inputs, output)
|
| 299 |
+
topics.change(news_signal,inputs, output)
|
| 300 |
+
news_id_1.change(news_signal,inputs, output)
|
| 301 |
+
bt1.click(news_signal,inputs, output)
|
| 302 |
+
|
| 303 |
+
# btn_predict.change(fn_predict,[btn_predict],outputs= [row1,row2])
|
| 304 |
+
demo.load(news_signal,inputs, output)
|
| 305 |
+
with gr.Tab('Signal Forcasting'):
|
| 306 |
+
with gr.Row(variant='panel'):
|
| 307 |
+
with gr.Column():
|
| 308 |
+
news_id_2 = gr.Dropdown(list(newsAgenciesDic.values()),label='Select News Agency',value=list(newsAgenciesDic.values())[0])
|
| 309 |
+
topics_2 = gr.Dropdown(tags,label='Select Topic\'s Signal',value=tags[0],multiselect=False)
|
| 310 |
+
with gr.Row():
|
| 311 |
+
with gr.Column():
|
| 312 |
+
rangeYear1_2 = gr.Slider(minimum=2015,maximum=2022,step=1,value=2015,label='From Year')
|
| 313 |
+
with gr.Column():
|
| 314 |
+
rangeYear2_2 = gr.Slider(minimum=2016,maximum=2023,step=1,value=2023,label='To Year')
|
| 315 |
+
with gr.Column():
|
| 316 |
+
period_2 = gr.Radio(['Week','Month'],label='Select Grouping Period',value='Month')
|
| 317 |
+
normalize_2 = gr.Radio(['True','False'],label='Signal Normalization',value='False')
|
| 318 |
+
dfselector_2 = gr.Slider(minimum=1,maximum=3,step=1,value=2,label='Select Signal Sensitivity from 1 to 3')
|
| 319 |
+
predMode = gr.Radio(['STL','ARIMA','CTG1','CTG2'],label='Select Model Type',value='STL')
|
| 320 |
+
|
| 321 |
+
submit_btn = gr.Button("Signal Analysis")
|
| 322 |
+
|
| 323 |
+
inputs=[news_id_2,topics_2,dfselector_2,period_2,rangeYear1_2,rangeYear2_2,normalize_2,predMode]
|
| 324 |
+
with gr.Row():
|
| 325 |
+
|
| 326 |
+
output2 = gr.Plot()
|
| 327 |
+
|
| 328 |
+
submit_btn.click(news_signal_predict,inputs, output2)
|
| 329 |
+
|
| 330 |
+
with gr.Tab('Signal Correlation'):
|
| 331 |
+
with gr.Row(variant='panel'):
|
| 332 |
+
|
| 333 |
+
newsList=list(newsAgenciesDic.values())
|
| 334 |
+
news_id_3 = gr.Dropdown(newsList,label='Select News Agency 1',value=newsList[0])
|
| 335 |
+
newsList.insert(0,'none')
|
| 336 |
+
news_id_4 = gr.Dropdown(newsList,label='Select News Agency 2',value=newsList[0])
|
| 337 |
+
modelType = gr.Radio(['Tag','Sentiment','Emotion'],label='Model Type',value='Tag')
|
| 338 |
+
modelSel = gr.Radio(['Self-Supervised','Supervised'],label='Model Selection',value='Self-Supervised')
|
| 339 |
+
with gr.Row():
|
| 340 |
+
with gr.Column():
|
| 341 |
+
rangeYear1_3 = gr.Slider(minimum=2015,maximum=2022,step=1,value=2015,label='From Year')
|
| 342 |
+
with gr.Column():
|
| 343 |
+
rangeYear2_3 = gr.Slider(minimum=2016,maximum=2023,step=1,value=2023,label='To Year')
|
| 344 |
+
bt3=gr.Button()
|
| 345 |
+
with gr.Row():
|
| 346 |
+
output3 = gr.Plot()
|
| 347 |
+
bt3.click(news_signal_correlation,inputs=[news_id_3,news_id_4,rangeYear1_3,rangeYear2_3,modelType,modelSel],outputs=output3)
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
demo.launch()
|