File size: 1,480 Bytes
51a0039
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import gradio as gr


URL = "https://docs.google.com/spreadsheets/d/1pJPFxqbWeASWi4KZAPf7Go7b46y_7sHePmf-vPRD67I/edit?usp=sharing"
csv_url = URL.replace('/edit?usp=', '/export?format=csv&usp=')

def get_data():
  df = pd.read_csv(csv_url)
  df['Tweet Volume'] = df['Tweet Volume'].str[:-1]
  df['Tweet Volume'] = df['Tweet Volume'].transform( lambda x: x[-2:] if 'Under' in x else x)
  df['Trending Topic / Hashtag'] = df['Trending Topic / Hashtag'].transform( lambda x: x.split()[0])
  df["Tweet Volume"] = pd.to_numeric(df["Tweet Volume"])
  df = df.sort_values(by=['Tweet Volume'], ascending=False)
  return df[["Trending Topic / Hashtag",	"Tweet Volume"]][:15]

with gr.Blocks() as demo:
    gr.Markdown("# 📈 Twitter Trends - Qatar using Real-Time Line and Scatter Plot")
    gr.Markdown("Following are the current top twitter trending topics in Qatar, Trends last updated every 30 minutes !")
    with gr.Row():
            gr.LinePlot(get_data, x="Trending Topic / Hashtag", y="Tweet Volume", tooltip=["Trending Topic / Hashtag","Tweet Volume"] , every=5, overlay_point=True, width=500, height=500, title='Real-Time Line Plot')
            gr.ScatterPlot(get_data, y="Tweet Volume", x="Trending Topic / Hashtag",  tooltip=["Trending Topic / Hashtag","Tweet Volume"] , every=5,  width=500, height=500, title='Real-Time Scatter Plot')
    with gr.Row():
        gr.DataFrame(get_data, every=5)
demo.queue().launch()  # Run the demo with queuing enabled