abadesalex commited on
Commit
1ad4e76
β€’
1 Parent(s): d0cfa36

bar graphs

Browse files
This view is limited to 50 files because it contains too many changes. Β  See raw diff
Files changed (50) hide show
  1. FastAPI/app/__pycache__/api.cpython-310.pyc +0 -0
  2. FastAPI/app/api.py +196 -9
  3. FastAPI/app/build/asset-manifest.json +3 -3
  4. FastAPI/app/build/index.html +1 -1
  5. FastAPI/app/{build_copy_v2/static/js/main.ed106e83.js β†’ build/static/js/main.4ec2654c.js} +0 -0
  6. FastAPI/app/{build_copy_v2/static/js/main.ed106e83.js.LICENSE.txt β†’ build/static/js/main.4ec2654c.js.LICENSE.txt} +0 -0
  7. FastAPI/app/build/static/js/main.4ec2654c.js.map +0 -0
  8. FastAPI/app/build/words.svg +0 -0
  9. FastAPI/app/build_copy_v1/index.html +0 -1
  10. FastAPI/app/build_copy_v1/static/js/main.e17bd3d9.js +0 -0
  11. FastAPI/app/build_copy_v1/static/js/main.e17bd3d9.js.LICENSE.txt +0 -39
  12. FastAPI/app/build_copy_v1/static/js/main.e17bd3d9.js.map +0 -0
  13. FastAPI/app/build_copy_v2/asset-manifest.json +0 -10
  14. FastAPI/app/build_copy_v2/favicon.ico +0 -0
  15. FastAPI/app/build_copy_v2/logo192.png +0 -0
  16. FastAPI/app/build_copy_v2/logo512.png +0 -0
  17. FastAPI/app/build_copy_v2/manifest.json +0 -25
  18. FastAPI/app/build_copy_v2/robots.txt +0 -3
  19. FastAPI/app/build_copy_v2/static/js/main.ed106e83.js.map +0 -0
  20. FastAPI/app/build_copy_v3/asset-manifest.json +0 -10
  21. FastAPI/app/build_copy_v3/favicon.ico +0 -0
  22. FastAPI/app/build_copy_v3/index.html +0 -1
  23. FastAPI/app/build_copy_v3/logo192.png +0 -0
  24. FastAPI/app/build_copy_v3/logo512.png +0 -0
  25. FastAPI/app/build_copy_v3/manifest.json +0 -25
  26. FastAPI/app/build_copy_v3/robots.txt +0 -3
  27. FastAPI/app/build_copy_v3/static/js/main.98763516.js +0 -0
  28. FastAPI/app/build_copy_v3/static/js/main.98763516.js.LICENSE.txt +0 -136
  29. FastAPI/app/build_copy_v3/static/js/main.98763516.js.map +0 -0
  30. FastAPI/app/{build_copy_v1 β†’ build_v2}/asset-manifest.json +3 -3
  31. FastAPI/app/{build_copy_v1 β†’ build_v2}/favicon.ico +0 -0
  32. FastAPI/app/{build_copy_v2 β†’ build_v2}/index.html +1 -1
  33. FastAPI/app/{build_copy_v1 β†’ build_v2}/logo192.png +0 -0
  34. FastAPI/app/{build_copy_v1 β†’ build_v2}/logo512.png +0 -0
  35. FastAPI/app/{build_copy_v1 β†’ build_v2}/manifest.json +0 -0
  36. FastAPI/app/{build_copy_v1 β†’ build_v2}/robots.txt +0 -0
  37. FastAPI/app/{build β†’ build_v2}/static/js/main.76e15e36.js +0 -0
  38. FastAPI/app/{build β†’ build_v2}/static/js/main.76e15e36.js.LICENSE.txt +0 -0
  39. FastAPI/app/{build β†’ build_v2}/static/js/main.76e15e36.js.map +0 -0
  40. FastAPI/app/utils/__pycache__/embedding.cpython-310.pyc +0 -0
  41. FastAPI/app/utils/embedding.py +13 -3
  42. FastAPI/test.ipynb +0 -0
  43. my-app/package-lock.json +38 -0
  44. my-app/package.json +1 -0
  45. my-app/public/words.svg +0 -0
  46. my-app/src/Components/ActiveWords/index.jsx +99 -37
  47. my-app/src/Components/BarPlot/index.jsx +32 -0
  48. my-app/src/Components/Body/index.jsx +4 -3
  49. my-app/src/Components/CommonCategory/index.jsx +174 -0
  50. my-app/src/Components/Context/WordsContext.js +10 -0
FastAPI/app/__pycache__/api.cpython-310.pyc CHANGED
Binary files a/FastAPI/app/__pycache__/api.cpython-310.pyc and b/FastAPI/app/__pycache__/api.cpython-310.pyc differ
 
FastAPI/app/api.py CHANGED
@@ -1,13 +1,18 @@
1
- from fastapi import FastAPI, Query
 
 
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.staticfiles import StaticFiles
4
- from fastapi.responses import FileResponse
 
 
5
 
6
  from app.utils.embedding import get_embedding
7
 
8
 
9
  app = FastAPI()
10
 
 
11
  origins = [
12
  "http://localhost:3000",
13
  "http://localhost:8000",
@@ -38,17 +43,26 @@ words_db = []
38
 
39
 
40
  @app.get("/api/words", tags=["words"])
41
- async def get_todos() -> dict:
 
42
  return {"data": words_db}
43
 
44
 
45
  @app.post("/api/add-word", tags=["words"])
46
  async def add_word(word: dict) -> dict:
47
- words_db.append(word)
48
- word_to_embbed = word["id"]
49
- word_embedding = get_embedding(word_to_embbed)[:3]
50
- word["embedding"] = word_embedding.tolist()
51
- return {"data": {"Succesful"}}
 
 
 
 
 
 
 
 
52
 
53
 
54
  @app.delete("/api/delete-word/{word_id}", tags=["words"])
@@ -56,12 +70,185 @@ async def delete_word(word_id: str) -> dict:
56
  word_id = int(word_id)
57
  for word in words_db:
58
  if int(word["id"]) == word_id:
59
- print("found")
60
  words_db.remove(word)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  return {"data": {"Succesful"}}
 
62
  return {"data": {"Word not found"}}
63
 
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  if __name__ == "__main__":
66
  import uvicorn
67
 
 
1
+ from typing import List
2
+ from fastapi import FastAPI, HTTPException, Query, Request
3
+ from fastapi.exceptions import RequestValidationError
4
  from fastapi.middleware.cors import CORSMiddleware
5
  from fastapi.staticfiles import StaticFiles
6
+ from fastapi.responses import FileResponse, JSONResponse
7
+ import numpy as np
8
+ from pydantic import BaseModel, Field, conlist
9
 
10
  from app.utils.embedding import get_embedding
11
 
12
 
13
  app = FastAPI()
14
 
15
+
16
  origins = [
17
  "http://localhost:3000",
18
  "http://localhost:8000",
 
43
 
44
 
45
  @app.get("/api/words", tags=["words"])
46
+ async def get_words() -> dict:
47
+
48
  return {"data": words_db}
49
 
50
 
51
  @app.post("/api/add-word", tags=["words"])
52
  async def add_word(word: dict) -> dict:
53
+ try:
54
+ word_embedding = get_embedding(word["item"])
55
+ words_db.append(word)
56
+ word["embedding"] = word_embedding.tolist()
57
+
58
+ return JSONResponse(
59
+ status_code=200,
60
+ content={"message": "Item created successfully", "success": True},
61
+ )
62
+ except HTTPException as e:
63
+ raise e
64
+ except Exception as e:
65
+ raise HTTPException(status_code=500, detail=str(e))
66
 
67
 
68
  @app.delete("/api/delete-word/{word_id}", tags=["words"])
 
70
  word_id = int(word_id)
71
  for word in words_db:
72
  if int(word["id"]) == word_id:
 
73
  words_db.remove(word)
74
+
75
+ return {"data": {"Succesful"}}
76
+
77
+ return {"data": {"Word not found"}}
78
+
79
+
80
+ #### Category Words
81
+
82
+ common_category_words = []
83
+
84
+
85
+ @app.get("/api/common-category-words", tags=["category-words"])
86
+ async def get_common_category_words() -> dict:
87
+
88
+ return {"data": common_category_words}
89
+
90
+
91
+ @app.post("/api/add-common-category-words", tags=["category-words"])
92
+ async def add_common_category_words(new_word: dict) -> dict:
93
+ try:
94
+ for word in common_category_words:
95
+ if new_word["item"] == word["item"]:
96
+ raise HTTPException(status_code=400, detail="Word already exists")
97
+
98
+ word_embedding = get_embedding(new_word["item"])
99
+ new_word["embedding"] = word_embedding.tolist()
100
+ common_category_words.append(new_word)
101
+ return JSONResponse(
102
+ status_code=200,
103
+ content={"message": "Item created successfully", "success": True},
104
+ )
105
+ except HTTPException as e:
106
+ raise e
107
+ except Exception as e:
108
+ raise HTTPException(status_code=500, detail=str(e))
109
+
110
+
111
+ @app.get("/api/get-embedding", tags=["category-words"])
112
+ async def get_embedding_api() -> dict:
113
+ if len(common_category_words) > 1:
114
+ vectors = [word["embedding"] for word in common_category_words]
115
+ variances = np.var(vectors, axis=0)
116
+ low_variance_dims = np.argsort(variances)[:3]
117
+ result = {
118
+ "variances": variances.tolist(),
119
+ "top_variance_dims": low_variance_dims.tolist(),
120
+ }
121
+ return JSONResponse(status_code=200, content={"data": result, "success": True})
122
+ return JSONResponse(
123
+ status_code=200,
124
+ content={
125
+ "data": {"variances": [0] * 50, "top_variance_dims": [0, 1, 2]},
126
+ "message": "Not enough words for analysis",
127
+ "success": False,
128
+ },
129
+ )
130
+
131
+
132
+ @app.delete("/api/delete-common-category-words/{word_id}", tags=["category-words"])
133
+ async def delete_common_category_words(word_id: str) -> dict:
134
+ word_id = int(word_id)
135
+ for word in common_category_words:
136
+ if int(word["id"]) == word_id:
137
+ common_category_words.remove(word)
138
+
139
  return {"data": {"Succesful"}}
140
+
141
  return {"data": {"Word not found"}}
142
 
143
 
144
+ ### Difference Semantic
145
+
146
+ from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
147
+
148
+
149
+ class WordPair(BaseModel):
150
+ word1: str = Field(..., min_length=2)
151
+ word2: str = Field(..., min_length=2)
152
+
153
+
154
+ @app.exception_handler(RequestValidationError)
155
+ async def validation_exception_handler(request: Request, exc: RequestValidationError):
156
+ errors = exc.errors()
157
+ detailed_messages = [f"Error in {err['loc'][1]}: {err['msg']}" for err in errors]
158
+ print(detailed_messages)
159
+ return JSONResponse(
160
+ status_code=HTTP_422_UNPROCESSABLE_ENTITY,
161
+ content={"detail": ", ".join(detailed_messages), "body": exc.body},
162
+ )
163
+
164
+
165
+ semantic_difference_db = {}
166
+
167
+
168
+ @app.get("/api/difference-semantic-words", tags=["difference-semantic"])
169
+ async def get_semantic_difference() -> dict:
170
+
171
+ return JSONResponse(
172
+ status_code=200, content={"data": semantic_difference_db, "success": True}
173
+ )
174
+
175
+
176
+ @app.post("/api/add-difference-semantic-words", tags=["difference-semantic"])
177
+ async def add_semantic_difference(new_words: WordPair):
178
+ try:
179
+ first_word = new_words.word1
180
+ second_word = new_words.word2
181
+
182
+ combined_word = f"{first_word}-{second_word}"
183
+ word_one_embedding = get_embedding(first_word)
184
+ word_two_embedding = get_embedding(second_word)
185
+
186
+ embedding = word_one_embedding - word_two_embedding
187
+
188
+ if (
189
+ combined_word in semantic_difference_db
190
+ or combined_word[::-1] in semantic_difference_db
191
+ ):
192
+ raise HTTPException(
193
+ status_code=400, detail="Semantic difference already exists"
194
+ )
195
+ semantic_difference_db[combined_word] = {
196
+ "id": len(semantic_difference_db) + 1,
197
+ "word-1": first_word,
198
+ "word-2": second_word,
199
+ "embedding": embedding.tolist(),
200
+ }
201
+ return JSONResponse(
202
+ status_code=200,
203
+ content={"message": "Item created successfully", "success": True},
204
+ )
205
+ except HTTPException as e:
206
+ raise e
207
+ except Exception as e:
208
+ raise HTTPException(status_code=500, detail=str(e))
209
+
210
+
211
+ @app.get("/api/get-embedding-difference", tags=["difference-semantic"])
212
+ async def get_embedding_difference() -> dict:
213
+ try:
214
+ if len(semantic_difference_db) > 1:
215
+ vectors = [word["embedding"] for word in semantic_difference_db.values()]
216
+ variances = np.var(vectors, axis=0)
217
+ low_variance_dims = np.argsort(variances)[:3]
218
+ result = {
219
+ "variance": variances.tolist(),
220
+ "top_variance_dims": low_variance_dims.tolist(),
221
+ }
222
+ return JSONResponse(
223
+ status_code=200, content={"data": result, "success": True}
224
+ )
225
+ return JSONResponse(
226
+ status_code=200,
227
+ content={
228
+ "data": {"variance": [0] * 50, "top_variance_dims": [0, 1, 2]},
229
+ "message": "Not enough words for analysis",
230
+ "success": False,
231
+ },
232
+ )
233
+ except Exception as e:
234
+ raise HTTPException(status_code=500, detail=str(e))
235
+
236
+
237
+ @app.delete(
238
+ "/api/delete-difference-semantic-words/{word_id}", tags=["difference-semantic"]
239
+ )
240
+ async def delete_semantic_difference(word_id: str) -> dict:
241
+ try:
242
+ word_id = int(word_id)
243
+ for word in semantic_difference_db.values():
244
+ if int(word["id"]) == word_id:
245
+ del semantic_difference_db[word["word-1"] + "-" + word["word-2"]]
246
+ return {"data": {"Succesful"}}
247
+ return JSONResponse(status_code=404, content={"data": {"Word not found"}})
248
+ except Exception as e:
249
+ raise HTTPException(status_code=500, detail=str(e))
250
+
251
+
252
  if __name__ == "__main__":
253
  import uvicorn
254
 
FastAPI/app/build/asset-manifest.json CHANGED
@@ -1,10 +1,10 @@
1
  {
2
  "files": {
3
- "main.js": "/static/js/main.76e15e36.js",
4
  "index.html": "/index.html",
5
- "main.76e15e36.js.map": "/static/js/main.76e15e36.js.map"
6
  },
7
  "entrypoints": [
8
- "static/js/main.76e15e36.js"
9
  ]
10
  }
 
1
  {
2
  "files": {
3
+ "main.js": "/static/js/main.4ec2654c.js",
4
  "index.html": "/index.html",
5
+ "main.4ec2654c.js.map": "/static/js/main.4ec2654c.js.map"
6
  },
7
  "entrypoints": [
8
+ "static/js/main.4ec2654c.js"
9
  ]
10
  }
FastAPI/app/build/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.76e15e36.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
 
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.4ec2654c.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
FastAPI/app/{build_copy_v2/static/js/main.ed106e83.js β†’ build/static/js/main.4ec2654c.js} RENAMED
The diff for this file is too large to render. See raw diff
 
FastAPI/app/{build_copy_v2/static/js/main.ed106e83.js.LICENSE.txt β†’ build/static/js/main.4ec2654c.js.LICENSE.txt} RENAMED
File without changes
FastAPI/app/build/static/js/main.4ec2654c.js.map ADDED
The diff for this file is too large to render. See raw diff
 
FastAPI/app/build/words.svg ADDED
FastAPI/app/build_copy_v1/index.html DELETED
@@ -1 +0,0 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.e17bd3d9.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
 
 
FastAPI/app/build_copy_v1/static/js/main.e17bd3d9.js DELETED
The diff for this file is too large to render. See raw diff
 
FastAPI/app/build_copy_v1/static/js/main.e17bd3d9.js.LICENSE.txt DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * @license React
3
- * react-dom.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
-
11
- /**
12
- * @license React
13
- * react-jsx-runtime.production.min.js
14
- *
15
- * Copyright (c) Facebook, Inc. and its affiliates.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- */
20
-
21
- /**
22
- * @license React
23
- * react.production.min.js
24
- *
25
- * Copyright (c) Facebook, Inc. and its affiliates.
26
- *
27
- * This source code is licensed under the MIT license found in the
28
- * LICENSE file in the root directory of this source tree.
29
- */
30
-
31
- /**
32
- * @license React
33
- * scheduler.production.min.js
34
- *
35
- * Copyright (c) Facebook, Inc. and its affiliates.
36
- *
37
- * This source code is licensed under the MIT license found in the
38
- * LICENSE file in the root directory of this source tree.
39
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
FastAPI/app/build_copy_v1/static/js/main.e17bd3d9.js.map DELETED
The diff for this file is too large to render. See raw diff
 
FastAPI/app/build_copy_v2/asset-manifest.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "files": {
3
- "main.js": "/static/js/main.ed106e83.js",
4
- "index.html": "/index.html",
5
- "main.ed106e83.js.map": "/static/js/main.ed106e83.js.map"
6
- },
7
- "entrypoints": [
8
- "static/js/main.ed106e83.js"
9
- ]
10
- }
 
 
 
 
 
 
 
 
 
 
 
FastAPI/app/build_copy_v2/favicon.ico DELETED
Binary file (3.87 kB)
 
FastAPI/app/build_copy_v2/logo192.png DELETED
Binary file (5.35 kB)
 
FastAPI/app/build_copy_v2/logo512.png DELETED
Binary file (9.66 kB)
 
FastAPI/app/build_copy_v2/manifest.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "short_name": "React App",
3
- "name": "Create React App Sample",
4
- "icons": [
5
- {
6
- "src": "favicon.ico",
7
- "sizes": "64x64 32x32 24x24 16x16",
8
- "type": "image/x-icon"
9
- },
10
- {
11
- "src": "logo192.png",
12
- "type": "image/png",
13
- "sizes": "192x192"
14
- },
15
- {
16
- "src": "logo512.png",
17
- "type": "image/png",
18
- "sizes": "512x512"
19
- }
20
- ],
21
- "start_url": ".",
22
- "display": "standalone",
23
- "theme_color": "#000000",
24
- "background_color": "#ffffff"
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
FastAPI/app/build_copy_v2/robots.txt DELETED
@@ -1,3 +0,0 @@
1
- # https://www.robotstxt.org/robotstxt.html
2
- User-agent: *
3
- Disallow:
 
 
 
 
FastAPI/app/build_copy_v2/static/js/main.ed106e83.js.map DELETED
The diff for this file is too large to render. See raw diff
 
FastAPI/app/build_copy_v3/asset-manifest.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "files": {
3
- "main.js": "/static/js/main.98763516.js",
4
- "index.html": "/index.html",
5
- "main.98763516.js.map": "/static/js/main.98763516.js.map"
6
- },
7
- "entrypoints": [
8
- "static/js/main.98763516.js"
9
- ]
10
- }
 
 
 
 
 
 
 
 
 
 
 
FastAPI/app/build_copy_v3/favicon.ico DELETED
Binary file (3.87 kB)
 
FastAPI/app/build_copy_v3/index.html DELETED
@@ -1 +0,0 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.98763516.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
 
 
FastAPI/app/build_copy_v3/logo192.png DELETED
Binary file (5.35 kB)
 
FastAPI/app/build_copy_v3/logo512.png DELETED
Binary file (9.66 kB)
 
FastAPI/app/build_copy_v3/manifest.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "short_name": "React App",
3
- "name": "Create React App Sample",
4
- "icons": [
5
- {
6
- "src": "favicon.ico",
7
- "sizes": "64x64 32x32 24x24 16x16",
8
- "type": "image/x-icon"
9
- },
10
- {
11
- "src": "logo192.png",
12
- "type": "image/png",
13
- "sizes": "192x192"
14
- },
15
- {
16
- "src": "logo512.png",
17
- "type": "image/png",
18
- "sizes": "512x512"
19
- }
20
- ],
21
- "start_url": ".",
22
- "display": "standalone",
23
- "theme_color": "#000000",
24
- "background_color": "#ffffff"
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
FastAPI/app/build_copy_v3/robots.txt DELETED
@@ -1,3 +0,0 @@
1
- # https://www.robotstxt.org/robotstxt.html
2
- User-agent: *
3
- Disallow:
 
 
 
 
FastAPI/app/build_copy_v3/static/js/main.98763516.js DELETED
The diff for this file is too large to render. See raw diff
 
FastAPI/app/build_copy_v3/static/js/main.98763516.js.LICENSE.txt DELETED
@@ -1,136 +0,0 @@
1
- /*
2
- * @copyright 2016 Sean Connelly (@voidqk), http://syntheti.cc
3
- * @license MIT
4
- * @preserve Project Home: https://github.com/voidqk/polybooljs
5
- */
6
-
7
- /*
8
- object-assign
9
- (c) Sindre Sorhus
10
- @license MIT
11
- */
12
-
13
- /*
14
- * @copyright 2016 Sean Connelly (@voidqk), http://syntheti.cc
15
- * @license MIT
16
- * @preserve Project Home: https://github.com/voidqk/polybooljs
17
- */
18
-
19
- /*!
20
- * The buffer module from node.js, for the browser.
21
- *
22
- * @author Feross Aboukhadijeh <https://feross.org>
23
- * @license MIT
24
- */
25
-
26
- /*!
27
- * Determine if an object is a Buffer
28
- *
29
- * @author Feross Aboukhadijeh <https://feross.org>
30
- * @license MIT
31
- */
32
-
33
- /*!
34
- * pad-left <https://github.com/jonschlinkert/pad-left>
35
- *
36
- * Copyright (c) 2014-2015, Jon Schlinkert.
37
- * Licensed under the MIT license.
38
- */
39
-
40
- /*!
41
- * repeat-string <https://github.com/jonschlinkert/repeat-string>
42
- *
43
- * Copyright (c) 2014-2015, Jon Schlinkert.
44
- * Licensed under the MIT License.
45
- */
46
-
47
- /*!
48
- * The buffer module from node.js, for the browser.
49
- *
50
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
51
- * @license MIT
52
- */
53
-
54
- /*!
55
- * The buffer module from node.js, for the browser.
56
- *
57
- * @author Feross Aboukhadijeh <https://feross.org>
58
- * @license MIT
59
- */
60
-
61
- /*! Native Promise Only
62
- v0.8.1 (c) Kyle Simpson
63
- MIT License: http://getify.mit-license.org
64
- */
65
-
66
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
67
-
68
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
69
-
70
- /**
71
- * @license React
72
- * react-dom.production.min.js
73
- *
74
- * Copyright (c) Facebook, Inc. and its affiliates.
75
- *
76
- * This source code is licensed under the MIT license found in the
77
- * LICENSE file in the root directory of this source tree.
78
- */
79
-
80
- /**
81
- * @license React
82
- * react-is.production.min.js
83
- *
84
- * Copyright (c) Facebook, Inc. and its affiliates.
85
- *
86
- * This source code is licensed under the MIT license found in the
87
- * LICENSE file in the root directory of this source tree.
88
- */
89
-
90
- /**
91
- * @license React
92
- * react-jsx-runtime.production.min.js
93
- *
94
- * Copyright (c) Facebook, Inc. and its affiliates.
95
- *
96
- * This source code is licensed under the MIT license found in the
97
- * LICENSE file in the root directory of this source tree.
98
- */
99
-
100
- /**
101
- * @license React
102
- * react.production.min.js
103
- *
104
- * Copyright (c) Facebook, Inc. and its affiliates.
105
- *
106
- * This source code is licensed under the MIT license found in the
107
- * LICENSE file in the root directory of this source tree.
108
- */
109
-
110
- /**
111
- * @license React
112
- * scheduler.production.min.js
113
- *
114
- * Copyright (c) Facebook, Inc. and its affiliates.
115
- *
116
- * This source code is licensed under the MIT license found in the
117
- * LICENSE file in the root directory of this source tree.
118
- */
119
-
120
- /** @license React v16.13.1
121
- * react-is.production.min.js
122
- *
123
- * Copyright (c) Facebook, Inc. and its affiliates.
124
- *
125
- * This source code is licensed under the MIT license found in the
126
- * LICENSE file in the root directory of this source tree.
127
- */
128
-
129
- /** @license React v17.0.2
130
- * react-is.production.min.js
131
- *
132
- * Copyright (c) Facebook, Inc. and its affiliates.
133
- *
134
- * This source code is licensed under the MIT license found in the
135
- * LICENSE file in the root directory of this source tree.
136
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
FastAPI/app/build_copy_v3/static/js/main.98763516.js.map DELETED
The diff for this file is too large to render. See raw diff
 
FastAPI/app/{build_copy_v1 β†’ build_v2}/asset-manifest.json RENAMED
@@ -1,10 +1,10 @@
1
  {
2
  "files": {
3
- "main.js": "/static/js/main.e17bd3d9.js",
4
  "index.html": "/index.html",
5
- "main.e17bd3d9.js.map": "/static/js/main.e17bd3d9.js.map"
6
  },
7
  "entrypoints": [
8
- "static/js/main.e17bd3d9.js"
9
  ]
10
  }
 
1
  {
2
  "files": {
3
+ "main.js": "/static/js/main.76e15e36.js",
4
  "index.html": "/index.html",
5
+ "main.76e15e36.js.map": "/static/js/main.76e15e36.js.map"
6
  },
7
  "entrypoints": [
8
+ "static/js/main.76e15e36.js"
9
  ]
10
  }
FastAPI/app/{build_copy_v1 β†’ build_v2}/favicon.ico RENAMED
File without changes
FastAPI/app/{build_copy_v2 β†’ build_v2}/index.html RENAMED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.ed106e83.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
 
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.76e15e36.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
FastAPI/app/{build_copy_v1 β†’ build_v2}/logo192.png RENAMED
File without changes
FastAPI/app/{build_copy_v1 β†’ build_v2}/logo512.png RENAMED
File without changes
FastAPI/app/{build_copy_v1 β†’ build_v2}/manifest.json RENAMED
File without changes
FastAPI/app/{build_copy_v1 β†’ build_v2}/robots.txt RENAMED
File without changes
FastAPI/app/{build β†’ build_v2}/static/js/main.76e15e36.js RENAMED
File without changes
FastAPI/app/{build β†’ build_v2}/static/js/main.76e15e36.js.LICENSE.txt RENAMED
File without changes
FastAPI/app/{build β†’ build_v2}/static/js/main.76e15e36.js.map RENAMED
File without changes
FastAPI/app/utils/__pycache__/embedding.cpython-310.pyc CHANGED
Binary files a/FastAPI/app/utils/__pycache__/embedding.cpython-310.pyc and b/FastAPI/app/utils/__pycache__/embedding.cpython-310.pyc differ
 
FastAPI/app/utils/embedding.py CHANGED
@@ -1,13 +1,23 @@
1
  import os
 
2
  import gensim.downloader as api
3
 
4
  # Ensure the environment variable is set correctly
5
- gensim_data_dir = os.getenv('GENSIM_DATA_DIR', '/home/user/gensim-data')
6
 
7
  # Load the GloVe model
8
  model = api.load("glove-wiki-gigaword-50")
9
 
10
 
11
- def get_embedding(word):
 
 
12
  global model
13
- return model[word]
 
 
 
 
 
 
 
 
1
  import os
2
+ from fastapi import HTTPException
3
  import gensim.downloader as api
4
 
5
  # Ensure the environment variable is set correctly
6
+ gensim_data_dir = os.getenv("GENSIM_DATA_DIR", "/home/user/gensim-data")
7
 
8
  # Load the GloVe model
9
  model = api.load("glove-wiki-gigaword-50")
10
 
11
 
12
+ def get_embedding(word: str) -> list:
13
+ min_val = -5.4593
14
+ max_val = 5.3101
15
  global model
16
+ try:
17
+ embediing = model[word.lower()]
18
+ # normalize vector min max to -1 to 1
19
+ embediing = (embediing - min_val) / (max_val - min_val) * 2 - 1
20
+ return embediing
21
+ except KeyError:
22
+ print("Word not in vocabulary")
23
+ raise HTTPException(status_code=404, detail="Word not in vocabulary")
FastAPI/test.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
my-app/package-lock.json CHANGED
@@ -15,6 +15,7 @@
15
  "@testing-library/jest-dom": "^5.17.0",
16
  "@testing-library/react": "^13.4.0",
17
  "@testing-library/user-event": "^13.5.0",
 
18
  "plotly.js": "^2.33.0",
19
  "react": "^18.3.1",
20
  "react-dom": "^18.3.1",
@@ -10665,6 +10666,14 @@
10665
  "escodegen": "^2.1.0"
10666
  }
10667
  },
 
 
 
 
 
 
 
 
10668
  "node_modules/gopd": {
10669
  "version": "1.0.1",
10670
  "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
@@ -14748,6 +14757,35 @@
14748
  "url": "https://github.com/sponsors/sindresorhus"
14749
  }
14750
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14751
  "node_modules/npm-run-path": {
14752
  "version": "4.0.1",
14753
  "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
 
15
  "@testing-library/jest-dom": "^5.17.0",
16
  "@testing-library/react": "^13.4.0",
17
  "@testing-library/user-event": "^13.5.0",
18
+ "notistack": "^3.0.1",
19
  "plotly.js": "^2.33.0",
20
  "react": "^18.3.1",
21
  "react-dom": "^18.3.1",
 
10666
  "escodegen": "^2.1.0"
10667
  }
10668
  },
10669
+ "node_modules/goober": {
10670
+ "version": "2.1.14",
10671
+ "resolved": "https://registry.npmjs.org/goober/-/goober-2.1.14.tgz",
10672
+ "integrity": "sha512-4UpC0NdGyAFqLNPnhCT2iHpza2q+RAY3GV85a/mRPdzyPQMsj0KmMMuetdIkzWRbJ+Hgau1EZztq8ImmiMGhsg==",
10673
+ "peerDependencies": {
10674
+ "csstype": "^3.0.10"
10675
+ }
10676
+ },
10677
  "node_modules/gopd": {
10678
  "version": "1.0.1",
10679
  "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
 
14757
  "url": "https://github.com/sponsors/sindresorhus"
14758
  }
14759
  },
14760
+ "node_modules/notistack": {
14761
+ "version": "3.0.1",
14762
+ "resolved": "https://registry.npmjs.org/notistack/-/notistack-3.0.1.tgz",
14763
+ "integrity": "sha512-ntVZXXgSQH5WYfyU+3HfcXuKaapzAJ8fBLQ/G618rn3yvSzEbnOB8ZSOwhX+dAORy/lw+GC2N061JA0+gYWTVA==",
14764
+ "dependencies": {
14765
+ "clsx": "^1.1.0",
14766
+ "goober": "^2.0.33"
14767
+ },
14768
+ "engines": {
14769
+ "node": ">=12.0.0",
14770
+ "npm": ">=6.0.0"
14771
+ },
14772
+ "funding": {
14773
+ "type": "opencollective",
14774
+ "url": "https://opencollective.com/notistack"
14775
+ },
14776
+ "peerDependencies": {
14777
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
14778
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
14779
+ }
14780
+ },
14781
+ "node_modules/notistack/node_modules/clsx": {
14782
+ "version": "1.2.1",
14783
+ "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz",
14784
+ "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==",
14785
+ "engines": {
14786
+ "node": ">=6"
14787
+ }
14788
+ },
14789
  "node_modules/npm-run-path": {
14790
  "version": "4.0.1",
14791
  "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
my-app/package.json CHANGED
@@ -10,6 +10,7 @@
10
  "@testing-library/jest-dom": "^5.17.0",
11
  "@testing-library/react": "^13.4.0",
12
  "@testing-library/user-event": "^13.5.0",
 
13
  "plotly.js": "^2.33.0",
14
  "react": "^18.3.1",
15
  "react-dom": "^18.3.1",
 
10
  "@testing-library/jest-dom": "^5.17.0",
11
  "@testing-library/react": "^13.4.0",
12
  "@testing-library/user-event": "^13.5.0",
13
+ "notistack": "^3.0.1",
14
  "plotly.js": "^2.33.0",
15
  "react": "^18.3.1",
16
  "react-dom": "^18.3.1",
my-app/public/words.svg ADDED
my-app/src/Components/ActiveWords/index.jsx CHANGED
@@ -1,65 +1,127 @@
1
- import { Grid, Typography } from "@mui/material";
 
2
  import { useEffect, useState } from "react";
 
 
 
3
  import { WordsContext } from "../Context/WordsContext";
4
- import CreateWordEmbedding from "../CreateWord/CreateWord";
5
- import WordCard from "../WordCard";
6
  import EmbeddingPlot from "../Plot";
 
7
 
8
- export default function ActiveWords() {
9
- const [words, setWords] = useState([]);
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- const fetchWords = async () => {
12
- const url = `https://abadesalex-emb-rep.hf.space/api/words`;
13
- // const url = "http://localhost:8000/api/words"
 
 
 
 
 
 
 
 
 
 
14
 
 
 
 
 
 
15
  const response = await fetch(url);
16
  const wordsResponse = await response.json();
17
- setWords(wordsResponse.data);
 
18
  };
19
 
20
- const deleteWord = async (id) => {
21
- const url = `https://abadesalex-emb-rep.hf.space/api/delete-word/${id}`;
22
- // const url = `http://localhost:8000/api/delete-word/${id}`
 
 
 
 
 
 
 
 
 
 
 
23
  await fetch(url, {
24
  method: "DELETE",
25
  headers: { "Content-Type": "application/json" },
26
  });
27
- await fetchWords();
28
  };
29
 
30
  useEffect(() => {
31
- fetchWords();
32
  }, []);
33
 
34
  return (
35
  <>
36
- <WordsContext.Provider value={{ words, fetchWords }}>
37
- <Grid container>
38
- <Grid item xs={8} container direction={"column"}>
39
- <Grid item>
40
- <CreateWordEmbedding />
41
- </Grid>
42
- <Grid item>
43
- <EmbeddingPlot words={words} />
44
- </Grid>
 
 
 
45
  </Grid>
46
- <Grid item xs={4}>
47
- <Grid item>
48
- <Typography variant={"h4"}>Active Words</Typography>
 
 
 
 
 
 
 
 
 
 
 
 
49
  </Grid>
50
- <Grid container direction={"column"} mt={2}>
51
- {words.map((word) => (
52
- <Grid item key={word.id} mb={1} mr={1}>
53
- <WordCard
54
- word={word.item}
55
- id={word.id}
56
- deleteWord={deleteWord}
57
- />
58
- </Grid>
59
- ))}
 
 
 
60
  </Grid>
61
  </Grid>
62
- </Grid>
63
  </WordsContext.Provider>
64
  </>
65
  );
 
1
+ import { Grid, ThemeProvider, Typography } from "@mui/material";
2
+ import { useSnackbar } from "notistack";
3
  import { useEffect, useState } from "react";
4
+ import { buildTheme } from "../../infrastructure/theme/theme";
5
+ import baseUrl from "../../services/api/api.config";
6
+ import postData from "../../services/api/base";
7
  import { WordsContext } from "../Context/WordsContext";
8
+ import IntroWordRepresentation from "../CreateWord/CreateWord";
9
+ import DimensionsList from "../DimensionList";
10
  import EmbeddingPlot from "../Plot";
11
+ import WordCard from "../WordCard";
12
 
13
+ export default function WordsVectorized() {
14
+ const [wordsVectorized, setWordsVectorized] = useState([]);
15
+ const [selectedDimensions, setSelectedDimensions] = useState([1, 2, 3]);
16
+ const { enqueueSnackbar } = useSnackbar();
17
+ const [wordOne, setWordOne] = useState("");
18
+ const [variance, setVariance] = useState({
19
+ variances: new Array(50).fill(0),
20
+ dimensions: [1, 2, 3],
21
+ });
22
+
23
+ const onChangeWordOne = (event) => {
24
+ const newWordOne = event.target.value;
25
+ setWordOne(newWordOne);
26
+ };
27
 
28
+ const onPressButton = () => {
29
+ const url = `/add-word`;
30
+ const data = {
31
+ id: wordsVectorized.length + 1,
32
+ item: wordOne,
33
+ };
34
+ postData(url, data)
35
+ .then(fetchWordsVectorized)
36
+ .catch((error) => {
37
+ enqueueSnackbar(error.detail || error.message, {
38
+ variant: "error",
39
+ });
40
+ });
41
 
42
+ setWordOne("");
43
+ };
44
+
45
+ const fetchWordsVectorized = async () => {
46
+ const url = `${baseUrl}/words`;
47
  const response = await fetch(url);
48
  const wordsResponse = await response.json();
49
+ setWordsVectorized(wordsResponse.data);
50
+ console.log(wordsResponse.data);
51
  };
52
 
53
+ const handleDimensionClick = (dimension) => {
54
+ setSelectedDimensions((prev) => {
55
+ if (prev.includes(dimension)) {
56
+ return prev.filter((dim) => dim !== dimension);
57
+ } else if (prev.length < 3) {
58
+ return [...prev, dimension];
59
+ } else {
60
+ return [prev[1], prev[2], dimension];
61
+ }
62
+ });
63
+ };
64
+
65
+ const deleteWordsVectorized = async (id) => {
66
+ const url = `${baseUrl}/delete-word/${id}`;
67
  await fetch(url, {
68
  method: "DELETE",
69
  headers: { "Content-Type": "application/json" },
70
  });
71
+ await fetchWordsVectorized();
72
  };
73
 
74
  useEffect(() => {
75
+ fetchWordsVectorized();
76
  }, []);
77
 
78
  return (
79
  <>
80
+ <WordsContext.Provider
81
+ value={{ words: wordsVectorized, fetchWords: fetchWordsVectorized }}
82
+ >
83
+ <ThemeProvider theme={buildTheme()}>
84
+ <Grid item textAlign={"center"} mb={5}>
85
+ <Typography
86
+ variant="h0"
87
+ color="#000"
88
+ sx={{ borderBottom: "2px solid #000" }}
89
+ >
90
+ Word Representation
91
+ </Typography>
92
  </Grid>
93
+ <Grid container>
94
+ <Grid item container direction={"column"}>
95
+ <IntroWordRepresentation
96
+ wordOne={wordOne}
97
+ onChangeWordOne={onChangeWordOne}
98
+ onPressButton={onPressButton}
99
+ />
100
+ </Grid>
101
+ <DimensionsList
102
+ embedding={variance.variances}
103
+ selectedDimensions={selectedDimensions}
104
+ onDimensionClick={handleDimensionClick}
105
+ />
106
+ <Grid item xs={9}>
107
+ <EmbeddingPlot words={wordsVectorized} x={selectedDimensions[0]} y={selectedDimensions[1]} z={selectedDimensions[2]} />
108
  </Grid>
109
+
110
+ <Grid item xs={3}>
111
+ <Grid container direction={"column"} mt={2}>
112
+ {wordsVectorized.map((word) => (
113
+ <Grid item key={word.id} mb={1} mr={1}>
114
+ <WordCard
115
+ word={word.item}
116
+ id={word.id}
117
+ deleteWord={deleteWordsVectorized}
118
+ />
119
+ </Grid>
120
+ ))}
121
+ </Grid>
122
  </Grid>
123
  </Grid>
124
+ </ThemeProvider>
125
  </WordsContext.Provider>
126
  </>
127
  );
my-app/src/Components/BarPlot/index.jsx ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Grid } from "@mui/material";
2
+ import Plot from "react-plotly.js";
3
+
4
+ export default function BarPlot({ variance }) {
5
+ const dimensions = Array.from({ length: variance.length }, (_, i) => i + 1);
6
+
7
+ return (
8
+ <>
9
+ <Grid item xs={12}>
10
+ <Plot
11
+ data={[
12
+ {
13
+ x: dimensions,
14
+ y: variance,
15
+ type: "bar",
16
+ marker: { color: "blue" },
17
+ },
18
+ ]}
19
+ layout={{
20
+ title: "Variance across dimensions",
21
+ xaxis: { title: "Dimension" },
22
+ yaxis: { title: "Variance" },
23
+ showlegend: false, // Remove legend
24
+ autosize: true, // Enable autosizing
25
+ }}
26
+ useResizeHandler={true}
27
+ style={{ width: "100%", height: "100%" }}
28
+ />
29
+ </Grid>
30
+ </>
31
+ );
32
+ }
my-app/src/Components/Body/index.jsx CHANGED
@@ -1,13 +1,14 @@
1
  import { Grid } from "@mui/material";
 
 
2
  import ActiveWords from "../ActiveWords";
3
- import CreateWordEmbedding from "../CreateWord/CreateWord";
4
  import { WordsContext } from "../Context/WordsContext";
5
- import { useEffect, useState } from "react";
6
 
7
  export default function Body() {
8
  const [words, setWords] = useState([]);
9
  const fetchWords = async () => {
10
- const response = await fetch("http://localhost:8000/api/words");
11
  const words = await response.json();
12
  setWords(words.data);
13
  };
 
1
  import { Grid } from "@mui/material";
2
+ import { useEffect, useState } from "react";
3
+ import baseUrl from "../../services/api/api.config";
4
  import ActiveWords from "../ActiveWords";
 
5
  import { WordsContext } from "../Context/WordsContext";
6
+ import CreateWordEmbedding from "../CreateWord/CreateWord";
7
 
8
  export default function Body() {
9
  const [words, setWords] = useState([]);
10
  const fetchWords = async () => {
11
+ const url = `${baseUrl}/words`;
12
  const words = await response.json();
13
  setWords(words.data);
14
  };
my-app/src/Components/CommonCategory/index.jsx ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ThemeProvider } from "@emotion/react";
2
+ import { Button, Grid, TextField, Typography } from "@mui/material";
3
+ import { useSnackbar } from "notistack";
4
+ import { useEffect, useState } from "react";
5
+ import { buildTheme } from "../../infrastructure/theme/theme";
6
+ import baseUrl from "../../services/api/api.config";
7
+ import postData from "../../services/api/base";
8
+ import BarPlot from "../BarPlot";
9
+ import { CommonCategoryWordsContext } from "../Context/WordsContext";
10
+ import DimensionsList from "../DimensionList";
11
+ import ScatterPlot from "../ScatterPlot";
12
+ import WordCard from "../WordCard";
13
+
14
+ export default function CommonCategory() {
15
+ const [CommonCategoryWords, setCommonCategoryWords] = useState([]);
16
+ const [wordOne, setWordOne] = useState("");
17
+ const { enqueueSnackbar } = useSnackbar();
18
+ const [variance, setVariance] = useState({
19
+ variances: new Array(50).fill(0),
20
+ dimensions: [1, 2, 3],
21
+ });
22
+
23
+ const [selectedDimensions, setSelectedDimensions] = useState([0, 0]);
24
+
25
+ const handleDimensionClick = (dimension) => {
26
+ setSelectedDimensions((prev) => {
27
+ if (prev.includes(dimension)) {
28
+ return prev.filter((dim) => dim !== dimension);
29
+ } else if (prev.length < 2) {
30
+ return [...prev, dimension];
31
+ } else {
32
+ return [prev[1], dimension];
33
+ }
34
+ });
35
+ };
36
+
37
+ const fetchCommonCategoryWords = async () => {
38
+ const url = `${baseUrl}/common-category-words`;
39
+ const response = await fetch(url);
40
+ const CommonCategoryWordsResponse = await response.json();
41
+ setCommonCategoryWords(CommonCategoryWordsResponse.data);
42
+ };
43
+
44
+ const fetchEmebedding = async () => {
45
+ const url = `${baseUrl}/get-embedding`;
46
+ const response = await fetch(url);
47
+ const embeddingResponse = await response.json();
48
+ setVariance(embeddingResponse.data);
49
+ setSelectedDimensions(embeddingResponse.data.top_variance_dims.slice(0, 2));
50
+ if (!embeddingResponse.success) {
51
+ enqueueSnackbar("Not enough word to create variance");
52
+ }
53
+ };
54
+
55
+ const deleteCommonCategoryWord = async (id) => {
56
+ const url = `${baseUrl}/delete-common-category-words/${id}`;
57
+ await fetch(url, {
58
+ method: "DELETE",
59
+ headers: { "Content-Type": "application/json" },
60
+ });
61
+ await fetchCommonCategoryWords();
62
+ await fetchEmebedding();
63
+ };
64
+
65
+ const onPressButton = async () => {
66
+ const url = `/add-common-category-words`;
67
+ const newWord = {
68
+ id: CommonCategoryWords.length + 1,
69
+ item: wordOne,
70
+ };
71
+
72
+ postData(url, newWord)
73
+ .then(fetchCommonCategoryWords)
74
+ .then(fetchEmebedding)
75
+ .catch((error) => {
76
+ enqueueSnackbar(error.detail || error.message, { variant: "error" });
77
+ });
78
+ };
79
+
80
+ useEffect(() => {
81
+ fetchCommonCategoryWords();
82
+ }, []);
83
+
84
+ const onChangeWordOne = (event) => {
85
+ const newWordOne = event.target.value;
86
+ setWordOne(newWordOne);
87
+ };
88
+
89
+ return (
90
+ <>
91
+ <CommonCategoryWordsContext.Provider
92
+ value={{ CommonCategoryWords, setCommonCategoryWords }}
93
+ >
94
+ <ThemeProvider theme={buildTheme()}>
95
+ <Grid
96
+ container
97
+ direction={"column"}
98
+ justifyContent={"center"}
99
+ alignItems={"center"}
100
+ spacing={2}
101
+ p={4}
102
+ >
103
+ <Grid item mb={2}>
104
+ <Typography variant="h0" color="#000">
105
+ Common Category
106
+ </Typography>
107
+ </Grid>
108
+ <Grid container textAlign={"center"} spacing={2}>
109
+ <Grid item xs={5}>
110
+ <TextField
111
+ id="word-one"
112
+ label="Word"
113
+ variant="outlined"
114
+ onChange={onChangeWordOne}
115
+ fullWidth
116
+ />
117
+ </Grid>
118
+
119
+ <Grid item xs={4}>
120
+ <Button
121
+ variant="contained"
122
+ color="primary"
123
+ fullWidth
124
+ sx={{ height: "100%" }}
125
+ onClick={onPressButton}
126
+ >
127
+ Create Embedding
128
+ </Button>
129
+ </Grid>
130
+ <Grid item xs={3}>
131
+ <Typography
132
+ variant="h0"
133
+ color="#000"
134
+ sx={{ borderBottom: "2px solid #000" }}
135
+ >
136
+ Active Words's List
137
+ </Typography>
138
+ </Grid>
139
+ </Grid>
140
+ <Grid container mt={2} textAlign={"center"} spacing={2}>
141
+ <Grid item xs={9}>
142
+ <BarPlot variance={variance.variances} ini />
143
+ </Grid>
144
+
145
+ <Grid item xs={3}>
146
+ {CommonCategoryWords.map((word) => (
147
+ <Grid item key={word.id} mb={1} ml={4}>
148
+ <WordCard
149
+ word={word.item}
150
+ id={word.id}
151
+ deleteWord={deleteCommonCategoryWord}
152
+ />
153
+ </Grid>
154
+ ))}
155
+ </Grid>
156
+ </Grid>
157
+ <DimensionsList
158
+ embedding={variance.variances}
159
+ selectedDimensions={selectedDimensions}
160
+ onDimensionClick={handleDimensionClick}
161
+ />
162
+ <Grid item xs={12} container>
163
+ <ScatterPlot
164
+ words={CommonCategoryWords}
165
+ x={selectedDimensions[0]}
166
+ y={selectedDimensions[1]}
167
+ />
168
+ </Grid>
169
+ </Grid>
170
+ </ThemeProvider>
171
+ </CommonCategoryWordsContext.Provider>
172
+ </>
173
+ );
174
+ }
my-app/src/Components/Context/WordsContext.js CHANGED
@@ -4,3 +4,13 @@ export const WordsContext = createContext({
4
  words: [],
5
  fetchWords: () => {},
6
  });
 
 
 
 
 
 
 
 
 
 
 
4
  words: [],
5
  fetchWords: () => {},
6
  });
7
+
8
+ export const CommonCategoryWordsContext = createContext({
9
+ CommonCategoryWords: [],
10
+ setCommonCategoryWords: () => {},
11
+ });
12
+
13
+ export const SemanticDifferencesContext = createContext({
14
+ SemanticDifferences: [],
15
+ setSemanticDifferences: () => {},
16
+ });