wilmerags commited on
Commit
9c5d67e
1 Parent(s): dd9138c

feat: Improving ui messages for non-technical comm

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -63,11 +63,12 @@ def draw_interactive_scatter_plot(
63
 
64
  # Up to here
65
  def generate_plot(
66
- df: List[str],
67
  model: SentenceTransformer,
 
68
  ) -> Figure:
69
- with st.spinner(text="Embedding text..."):
70
- embeddings = embed_text(df, model)
71
  # encoded_labels = encode_labels(labels)
72
  cluster = hdbscan.HDBSCAN(
73
  min_cluster_size=5,
@@ -75,16 +76,17 @@ def generate_plot(
75
  cluster_selection_method='eom'
76
  ).fit(embeddings)
77
  encoded_labels = cluster.labels_
78
- with st.spinner("Reducing dimensionality..."):
79
  embeddings_2d = get_tsne_embeddings(embeddings)
80
  plot = draw_interactive_scatter_plot(
81
- df, embeddings_2d[:, 0], embeddings_2d[:, 1], encoded_labels, encoded_labels, 'text', 'label'
82
  )
83
  return plot
84
 
85
 
86
  st.title("Tweet-SNEst")
87
  st.write("Visualize tweets embeddings in 2D using colors for topics labels.")
 
88
  col1, col2 = st.columns(2)
89
  with col1:
90
  tw_user = st.text_input("Twitter handle", "huggingface")
@@ -117,5 +119,5 @@ if tw_user:
117
  tweets_objs += tweets_response.data
118
  tweets_txt = [tweet.text for tweet in tweets_objs]
119
  # plot = generate_plot(df, text_column, label_column, sample, dimensionality_reduction_function, model)
120
- plot = generate_plot(tweets_txt, model)
121
  st.bokeh_chart(plot)
 
63
 
64
  # Up to here
65
  def generate_plot(
66
+ tws: List[str],
67
  model: SentenceTransformer,
68
+ tw_user: str
69
  ) -> Figure:
70
+ with st.spinner(text=f"Trying to understand '{tw_user}' tweets..."):
71
+ embeddings = embed_text(tws, model)
72
  # encoded_labels = encode_labels(labels)
73
  cluster = hdbscan.HDBSCAN(
74
  min_cluster_size=5,
 
76
  cluster_selection_method='eom'
77
  ).fit(embeddings)
78
  encoded_labels = cluster.labels_
79
+ with st.spinner("Now trying to express them with my own words..."):
80
  embeddings_2d = get_tsne_embeddings(embeddings)
81
  plot = draw_interactive_scatter_plot(
82
+ tws, embeddings_2d[:, 0], embeddings_2d[:, 1], encoded_labels, encoded_labels, 'text', 'label'
83
  )
84
  return plot
85
 
86
 
87
  st.title("Tweet-SNEst")
88
  st.write("Visualize tweets embeddings in 2D using colors for topics labels.")
89
+ st.caption('Please beware this is using Twitter free version of their API and might be needed to wait sometimes.')
90
  col1, col2 = st.columns(2)
91
  with col1:
92
  tw_user = st.text_input("Twitter handle", "huggingface")
 
119
  tweets_objs += tweets_response.data
120
  tweets_txt = [tweet.text for tweet in tweets_objs]
121
  # plot = generate_plot(df, text_column, label_column, sample, dimensionality_reduction_function, model)
122
+ plot = generate_plot(tweets_txt, model, tw_user)
123
  st.bokeh_chart(plot)