Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,24 +12,24 @@ HFTOKEN = os.environ["HF_TOKEN"]
|
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
def T_on_select(x, evt: gr.SelectData):
|
| 35 |
if evt.index[1] == 3:
|
|
@@ -168,30 +168,30 @@ def qa_summarise(selected_queries, qa_llm_model, text_field, data_df):
|
|
| 168 |
|
| 169 |
|
| 170 |
with gr.Blocks(fill_width=True) as demo:
|
| 171 |
-
js = """
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
"""
|
| 195 |
|
| 196 |
demo.load(None,None,None,js=js)
|
| 197 |
|
|
@@ -229,7 +229,7 @@ with gr.Blocks(fill_width=True) as demo:
|
|
| 229 |
with gr.Row():
|
| 230 |
with gr.Column(scale=4):
|
| 231 |
T_data_filter = gr.Dropdown(visible=False)
|
| 232 |
-
T_tweet_embed = gr.HTML() #"""<div id="tweet-container"></div>"""
|
| 233 |
# gr.ClearButton(components=T_tweet_embed)
|
| 234 |
|
| 235 |
with gr.Column(scale=6):
|
|
@@ -382,7 +382,13 @@ with gr.Blocks(fill_width=True) as demo:
|
|
| 382 |
|
| 383 |
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
|
|
|
| 386 |
# Test event listeners
|
| 387 |
T_predict_button.click(
|
| 388 |
load_and_classify_csv_dataframe,
|
|
@@ -390,9 +396,9 @@ with gr.Blocks(fill_width=True) as demo:
|
|
| 390 |
outputs=[T_data, T_data_ss_state, T_data_filter]
|
| 391 |
)
|
| 392 |
|
| 393 |
-
T_data.select(T_on_select,
|
| 394 |
-
|
| 395 |
-
|
| 396 |
# T_data.select(
|
| 397 |
# fn=lambda: gr.update(value=""),
|
| 398 |
# outputs=T_tweet_embed).then(T_on_select, None, T_tweet_embed).then(fn=None, js="reloadTwitterWidgets()")
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
+
js = """
|
| 16 |
+
async () => {
|
| 17 |
+
// Load Twitter Widgets script
|
| 18 |
+
const script = document.createElement("script");
|
| 19 |
+
script.onload = () => console.log("Twitter Widgets.js loaded");
|
| 20 |
+
script.src = "https://platform.twitter.com/widgets.js";
|
| 21 |
+
document.head.appendChild(script);
|
| 22 |
+
|
| 23 |
+
// Define a global function to reload Twitter widgets
|
| 24 |
+
globalThis.reloadTwitterWidgets = () => {
|
| 25 |
+
// Reload Twitter widgets
|
| 26 |
+
if (window.twttr && twttr.widgets) {
|
| 27 |
+
twttr.widgets.load();
|
| 28 |
+
}
|
| 29 |
|
| 30 |
+
};
|
| 31 |
+
}
|
| 32 |
+
"""
|
| 33 |
|
| 34 |
def T_on_select(x, evt: gr.SelectData):
|
| 35 |
if evt.index[1] == 3:
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
with gr.Blocks(fill_width=True) as demo:
|
| 171 |
+
# js = """
|
| 172 |
+
# async () => {
|
| 173 |
+
# // Load Twitter Widgets script
|
| 174 |
+
# const script = document.createElement("script");
|
| 175 |
+
# script.onload = () => console.log("Twitter Widgets.js loaded");
|
| 176 |
+
# script.src = "https://platform.twitter.com/widgets.js";
|
| 177 |
+
# document.head.appendChild(script);
|
| 178 |
|
| 179 |
+
# // Define a global function to reload Twitter widgets
|
| 180 |
+
# globalThis.reloadTwitterWidgets = (x) => {
|
| 181 |
+
# // Select the container where tweets are inserted
|
| 182 |
+
# const tweetContainer = document.getElementById("tweet-container");
|
| 183 |
|
| 184 |
+
# if (tweetContainer) {
|
| 185 |
+
# tweetContainer.innerHTML = ""; // Clear previous tweets
|
| 186 |
+
# }
|
| 187 |
|
| 188 |
+
# // Reload Twitter widgets
|
| 189 |
+
# if (window.twttr && twttr.widgets) {
|
| 190 |
+
# twttr.widgets.load();
|
| 191 |
+
# }
|
| 192 |
+
# };
|
| 193 |
+
# }
|
| 194 |
+
# """
|
| 195 |
|
| 196 |
demo.load(None,None,None,js=js)
|
| 197 |
|
|
|
|
| 229 |
with gr.Row():
|
| 230 |
with gr.Column(scale=4):
|
| 231 |
T_data_filter = gr.Dropdown(visible=False)
|
| 232 |
+
T_tweet_embed = gr.HTML("""<div id="tweet-container"></div>""") #"""<div id="tweet-container"></div>"""
|
| 233 |
# gr.ClearButton(components=T_tweet_embed)
|
| 234 |
|
| 235 |
with gr.Column(scale=6):
|
|
|
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
+
m_js = """ (x) = >
|
| 386 |
+
{
|
| 387 |
+
reloadTwitterWidgets();
|
| 388 |
+
twttr.widgets.createTweet(x,document.getElementById('tweet-container'),{theme: 'dark'});
|
| 389 |
+
}
|
| 390 |
|
| 391 |
+
"""
|
| 392 |
# Test event listeners
|
| 393 |
T_predict_button.click(
|
| 394 |
load_and_classify_csv_dataframe,
|
|
|
|
| 396 |
outputs=[T_data, T_data_ss_state, T_data_filter]
|
| 397 |
)
|
| 398 |
|
| 399 |
+
# T_data.select(T_on_select, None, T_tweet_embed)#.then(fn=None, js="reloadTwitterWidgets()")
|
| 400 |
+
T_data.select(T_on_select, None, T_tweetID)
|
| 401 |
+
T_tweetID.change(fn=None, inputs=T_tweetID, outputs=None, js=m_js)#.then(fn=None, inputs=T_tweetID, outputs=None, js="(x) => twttr.widgets.createTweet(x,document.getElementById('tweet-container'),{theme: 'dark'});")
|
| 402 |
# T_data.select(
|
| 403 |
# fn=lambda: gr.update(value=""),
|
| 404 |
# outputs=T_tweet_embed).then(T_on_select, None, T_tweet_embed).then(fn=None, js="reloadTwitterWidgets()")
|