Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,8 +34,8 @@ st.title('Biryani, Pizza, or Neither Classifier')
|
|
| 34 |
df = pd.read_csv("embeddings_receipes_final.csv")
|
| 35 |
|
| 36 |
# Check if the DataFrame is loaded correctly
|
| 37 |
-
if df.shape[1] <
|
| 38 |
-
st.error(f"Expected DataFrame with 385 columns, but got
|
| 39 |
else:
|
| 40 |
# Input text
|
| 41 |
input_text = st.text_area("Enter text to classify")
|
|
@@ -55,7 +55,7 @@ else:
|
|
| 55 |
# Display the result
|
| 56 |
st.write(f"The predicted label is: **{predicted_label}**")
|
| 57 |
|
| 58 |
-
# Visualization using t-SNE
|
| 59 |
embeddings = df.iloc[:, 1:-1].values # Exclude 'recipe_id' and 'label'
|
| 60 |
labels = df['label']
|
| 61 |
|
|
@@ -68,9 +68,11 @@ else:
|
|
| 68 |
indices = labels == label
|
| 69 |
plt.scatter(tsne_embeddings[indices, 0], tsne_embeddings[indices, 1], label=label)
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
| 74 |
|
| 75 |
plt.legend()
|
| 76 |
plt.title('2D t-SNE Visualization of Embeddings')
|
|
@@ -80,5 +82,3 @@ else:
|
|
| 80 |
|
| 81 |
else:
|
| 82 |
st.write("Please enter text to classify.")
|
| 83 |
-
|
| 84 |
-
|
|
|
|
| 34 |
df = pd.read_csv("embeddings_receipes_final.csv")
|
| 35 |
|
| 36 |
# Check if the DataFrame is loaded correctly
|
| 37 |
+
if df.shape[1] < 385: # 384 embeddings + 1 label + 1 recipe_id
|
| 38 |
+
st.error(f"Expected DataFrame with 385 columns, but got less than that. Please check your CSV file.")
|
| 39 |
else:
|
| 40 |
# Input text
|
| 41 |
input_text = st.text_area("Enter text to classify")
|
|
|
|
| 55 |
# Display the result
|
| 56 |
st.write(f"The predicted label is: **{predicted_label}**")
|
| 57 |
|
| 58 |
+
# Visualization using t-SNE
|
| 59 |
embeddings = df.iloc[:, 1:-1].values # Exclude 'recipe_id' and 'label'
|
| 60 |
labels = df['label']
|
| 61 |
|
|
|
|
| 68 |
indices = labels == label
|
| 69 |
plt.scatter(tsne_embeddings[indices, 0], tsne_embeddings[indices, 1], label=label)
|
| 70 |
|
| 71 |
+
# Project the input text embedding into the existing t-SNE space
|
| 72 |
+
tsne_input = TSNE(n_components=2, init='pca', random_state=42)
|
| 73 |
+
tsne_input_embedding = tsne_input.fit_transform(np.vstack([embeddings, embedding]))[-1]
|
| 74 |
+
|
| 75 |
+
plt.scatter(tsne_input_embedding[0], tsne_input_embedding[1], label='input text', c='red', marker='x', s=100)
|
| 76 |
|
| 77 |
plt.legend()
|
| 78 |
plt.title('2D t-SNE Visualization of Embeddings')
|
|
|
|
| 82 |
|
| 83 |
else:
|
| 84 |
st.write("Please enter text to classify.")
|
|
|
|
|
|