Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from mentions_dashboard import generate_mentions_dashboard
|
|
9 |
from gradio_utils import get_url_user_token
|
10 |
from Bubble_API_Calls import fetch_linkedin_token_from_bubble
|
11 |
|
12 |
-
from
|
13 |
|
14 |
# Fetch data
|
15 |
posts = fetch_linkedin_posts(client_id, token_dict)
|
@@ -55,6 +55,24 @@ def process_and_store_bubble_token(url_user_token, org_urn, token_state):
|
|
55 |
|
56 |
return check_token_status(new_state), new_state
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
def guarded_fetch_dashboard(token_state):
|
60 |
if not token_state or not token_state.get("token"):
|
@@ -96,6 +114,9 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
96 |
outputs=[status_box, token_state]
|
97 |
)
|
98 |
|
|
|
|
|
|
|
99 |
app.load(fn=check_token_status, inputs=[token_state], outputs=status_box)
|
100 |
gr.Timer(5.0).tick(fn=check_token_status, inputs=[token_state], outputs=status_box)
|
101 |
|
|
|
9 |
from gradio_utils import get_url_user_token
|
10 |
from Bubble_API_Calls import fetch_linkedin_token_from_bubble
|
11 |
|
12 |
+
from Linkedin_Data_API_Calls import fetch_linkedin_posts, fetch_linkedin_comments, analyze_sentiment, prepare_data_for_bubble, bulk_upload_to_bubble
|
13 |
|
14 |
# Fetch data
|
15 |
posts = fetch_linkedin_posts(client_id, token_dict)
|
|
|
55 |
|
56 |
return check_token_status(new_state), new_state
|
57 |
|
58 |
+
def guarded_fetch_posts(token_state):
|
59 |
+
if not token_state or not token_state.get("token"):
|
60 |
+
return "<p style='color:red; text-align:center;'>❌ Access denied. No token available.</p>"
|
61 |
+
|
62 |
+
client_id = token_state.get("client_id")
|
63 |
+
token_dict = token_state.get("token")
|
64 |
+
|
65 |
+
posts = fetch_linkedin_posts(client_id, token_dict)
|
66 |
+
comments_data = fetch_linkedin_comments(client_id, token_dict, [post["id"] for post in posts])
|
67 |
+
sentiments = analyze_sentiment(comments_data)
|
68 |
+
li_posts, li_post_stats, li_post_comments = prepare_data_for_bubble(posts, sentiments)
|
69 |
+
|
70 |
+
bulk_upload_to_bubble(li_posts, "LI_post")
|
71 |
+
bulk_upload_to_bubble(li_post_stats, "LI_post_stats")
|
72 |
+
bulk_upload_to_bubble(li_post_comments, "LI_post_comments")
|
73 |
+
|
74 |
+
return "<p style='color:green; text-align:center;'>✅ Posts and comments uploaded to Bubble.</p>"
|
75 |
+
|
76 |
|
77 |
def guarded_fetch_dashboard(token_state):
|
78 |
if not token_state or not token_state.get("token"):
|
|
|
114 |
outputs=[status_box, token_state]
|
115 |
)
|
116 |
|
117 |
+
fetch_dashboard_btn.click(fn=guarded_fetch_posts, inputs=[token_state], outputs=[dashboard_html])
|
118 |
+
|
119 |
+
|
120 |
app.load(fn=check_token_status, inputs=[token_state], outputs=status_box)
|
121 |
gr.Timer(5.0).tick(fn=check_token_status, inputs=[token_state], outputs=status_box)
|
122 |
|