Spaces:
Sleeping
Sleeping
nicer plot test
Browse files
app.py
CHANGED
@@ -24,13 +24,11 @@ default_texts = [
|
|
24 |
model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
|
25 |
|
26 |
# Function to compute document embeddings and apply PCA
|
27 |
-
# Modify the Gradio interface to accept a list of identifiers and texts
|
28 |
def compute_pca(data):
|
29 |
-
# data is expected to be a list of dictionaries with '
|
30 |
df = pd.DataFrame(data, columns=["Identifiant", "Texte"])
|
31 |
|
32 |
-
|
33 |
-
# Remove rows where 'Identifier' or 'Text' is empty or contains only whitespace
|
34 |
valid_entries = df[
|
35 |
(df['Identifiant'].str.strip() != '') &
|
36 |
(df['Texte'].str.strip() != '')
|
@@ -51,8 +49,18 @@ def compute_pca(data):
|
|
51 |
valid_entries['PC1'] = pca_result[:, 0]
|
52 |
valid_entries['PC2'] = pca_result[:, 1]
|
53 |
|
54 |
-
# Plot the PCA result with identifiers as labels
|
55 |
-
fig = px.scatter(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
return fig
|
57 |
|
58 |
def text_editor_app():
|
|
|
24 |
model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
|
25 |
|
26 |
# Function to compute document embeddings and apply PCA
|
|
|
27 |
def compute_pca(data):
|
28 |
+
# data is expected to be a list of dictionaries with 'Identifiant' and 'Texte' keys
|
29 |
df = pd.DataFrame(data, columns=["Identifiant", "Texte"])
|
30 |
|
31 |
+
# Remove rows where 'Identifiant' or 'Texte' is empty or contains only whitespace
|
|
|
32 |
valid_entries = df[
|
33 |
(df['Identifiant'].str.strip() != '') &
|
34 |
(df['Texte'].str.strip() != '')
|
|
|
49 |
valid_entries['PC1'] = pca_result[:, 0]
|
50 |
valid_entries['PC2'] = pca_result[:, 1]
|
51 |
|
52 |
+
# Plot the PCA result with identifiers as labels, with text positioned above the points
|
53 |
+
fig = px.scatter(
|
54 |
+
valid_entries,
|
55 |
+
x='PC1',
|
56 |
+
y='PC2',
|
57 |
+
text='Identifiant',
|
58 |
+
title='PCA des plongements sémantiques'
|
59 |
+
)
|
60 |
+
|
61 |
+
# Update the text position to be above the points
|
62 |
+
fig.update_traces(textposition='top center')
|
63 |
+
|
64 |
return fig
|
65 |
|
66 |
def text_editor_app():
|