marksverdhei commited on
Commit
bbb7e28
·
1 Parent(s): 2eb6e76

Update view

Browse files
Files changed (1) hide show
  1. views.py +8 -6
views.py CHANGED
@@ -42,6 +42,7 @@ def plot(df: pd.DataFrame, embeddings: np.ndarray, vectors_2d, reducer, correcto
42
  inferred_embedding = None
43
  # Add a card container to the right of the content with Streamlit columns
44
  col1, col2 = st.columns([0.6, 0.4]) # Adjusting ratio to allocate space for the card container
 
45
 
46
  with col1:
47
  # Main content stays here (scatterplot, form, etc.)
@@ -58,20 +59,17 @@ def plot(df: pd.DataFrame, embeddings: np.ndarray, vectors_2d, reducer, correcto
58
  vec = np.array([x, y]).astype("float32")
59
 
60
 
61
- submit_button = st.form_submit_button("Submit")
62
 
63
- if selected_points or submit_button:
64
  inferred_embedding = reducer.inverse_transform(np.array([[x, y]]) if not isinstance(reducer, UMAP) else np.array([[x, y]]))
65
  inferred_embedding = inferred_embedding.astype("float32")
66
 
67
- output = vec2text.invert_embeddings(
68
  embeddings=torch.tensor(inferred_embedding).cuda(),
69
  corrector=corrector,
70
  num_steps=20,
71
  )
72
-
73
- st.text(str(output))
74
- st.text(str(inferred_embedding))
75
  else:
76
  st.text("Click on a point in the scatterplot to see its coordinates.")
77
 
@@ -84,6 +82,10 @@ def plot(df: pd.DataFrame, embeddings: np.ndarray, vectors_2d, reducer, correcto
84
  f"### Selected text:\n```console\n{selected_sentence}\n```"
85
  )
86
 
 
 
 
 
87
  if inferred_embedding is not None and (closest_sentence_index != -1):
88
  couple = selected_sentence_embedding.squeeze(), inferred_embedding.squeeze()
89
  st.markdown(f"### Inferred embedding distance:")
 
42
  inferred_embedding = None
43
  # Add a card container to the right of the content with Streamlit columns
44
  col1, col2 = st.columns([0.6, 0.4]) # Adjusting ratio to allocate space for the card container
45
+ inversion_output_text = None
46
 
47
  with col1:
48
  # Main content stays here (scatterplot, form, etc.)
 
59
  vec = np.array([x, y]).astype("float32")
60
 
61
 
62
+ submit_button = st.form_submit_button("Synthesize")
63
 
64
+ if submit_button:
65
  inferred_embedding = reducer.inverse_transform(np.array([[x, y]]) if not isinstance(reducer, UMAP) else np.array([[x, y]]))
66
  inferred_embedding = inferred_embedding.astype("float32")
67
 
68
+ inversion_output_text, = vec2text.invert_embeddings(
69
  embeddings=torch.tensor(inferred_embedding).cuda(),
70
  corrector=corrector,
71
  num_steps=20,
72
  )
 
 
 
73
  else:
74
  st.text("Click on a point in the scatterplot to see its coordinates.")
75
 
 
82
  f"### Selected text:\n```console\n{selected_sentence}\n```"
83
  )
84
 
85
+ st.markdown(
86
+ f"### Synthesized text:\n```console\n{inversion_output_text}\n```"
87
+ )
88
+
89
  if inferred_embedding is not None and (closest_sentence_index != -1):
90
  couple = selected_sentence_embedding.squeeze(), inferred_embedding.squeeze()
91
  st.markdown(f"### Inferred embedding distance:")