jonathan@tuxmani.fr commited on
Commit
6950d8a
·
1 Parent(s): b947920

clean code

Browse files
amazon_this_object.egg-info/PKG-INFO ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: amazon-this-object
3
+ Version: 0.1.1
4
+ Summary: Get a link on Amazon, to buy a similar object you have.
5
+ Keywords: reachy-mini-app
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: reachy-mini
9
+ Requires-Dist: pathlib
10
+ Requires-Dist: fastapi
11
+
12
+ ---
13
+ title: Amazon This Object
14
+ emoji: 📦
15
+ colorFrom: red
16
+ colorTo: blue
17
+ sdk: static
18
+ pinned: false
19
+ short_description: Take a picture of an object and generate an Amazon link
20
+ tags:
21
+ - reachy_mini
22
+ - reachy_mini_python_app
23
+ ---
amazon_this_object.egg-info/SOURCES.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ README.md
2
+ pyproject.toml
3
+ ./amazon_this_object/__init__.py
4
+ ./amazon_this_object/main.py
5
+ ./amazon_this_object/static/index.html
6
+ ./amazon_this_object/static/main.js
7
+ ./amazon_this_object/static/style.css
8
+ amazon_this_object.egg-info/PKG-INFO
9
+ amazon_this_object.egg-info/SOURCES.txt
10
+ amazon_this_object.egg-info/dependency_links.txt
11
+ amazon_this_object.egg-info/entry_points.txt
12
+ amazon_this_object.egg-info/requires.txt
13
+ amazon_this_object.egg-info/top_level.txt
amazon_this_object.egg-info/dependency_links.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
amazon_this_object.egg-info/entry_points.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [reachy_mini_apps]
2
+ amazon-this-object = amazon_this_object.main:AmazonThisObject
amazon_this_object.egg-info/requires.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ reachy-mini
2
+ pathlib
3
+ fastapi
amazon_this_object.egg-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ amazon_this_object
amazon_this_object/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (178 Bytes). View file
 
amazon_this_object/__pycache__/main.cpython-312.pyc ADDED
Binary file (8.1 kB). View file
 
amazon_this_object/main.py CHANGED
@@ -29,7 +29,6 @@ class AmazonThisObject(ReachyMiniApp):
29
  image_url = f""
30
  exec_dir = os.path.abspath(__file__)
31
  exec_dir = exec_dir.replace("main.py","")
32
- print("exec_dir "+exec_dir)
33
  file_path = Path(exec_dir) / ".env"
34
 
35
  @self.settings_app.post("/set_token")
@@ -44,9 +43,7 @@ class AmazonThisObject(ReachyMiniApp):
44
  "message": "No token provided."
45
  }
46
 
47
- # Chemin du fichier .env dans le répertoire d'exécution
48
-
49
- # On écrase ou crée le fichier avec HF_TOKEN=ton_token
50
  with open(file_path, "w") as f:
51
  f.write(f"HF_TOKEN={token}\n")
52
  print(f"Token Hugging Face successfully saved in {file_path}")
@@ -60,33 +57,31 @@ class AmazonThisObject(ReachyMiniApp):
60
  "message": "Error on server side"
61
  }
62
 
63
- @self.settings_app.post("/check_token") # ou .get() si tu préfères, c'est plus logique pour une vérif
64
  async def hf_token_available(self_instance: AmazonThisObject = Depends(self._get_self)):
65
- file_path = Path(exec_dir) / ".env"
66
- if not file_path.exists():
67
- print(".env n'existe pas, ce con n'a pas encore mis son token.")
68
- return {
69
- "success": False,
70
  "token": None
71
- }
72
- try:
73
- # On lit tout le fichier
74
- with open(file_path, "r", encoding="utf-8") as f:
75
  lines = f.readlines()
76
- # On cherche la ligne HF_TOKEN=
77
- for line in lines:
78
  line = line.strip()
79
  if line.startswith("HF_TOKEN="):
80
  # On prend tout après le =
81
  self_instance.amaz_token = line.split("=", 1)[1].strip().strip('"').strip("'")
82
  break
83
- if self_instance.amaz_token:
84
- print("Token Hugging Face found. " + self_instance.amaz_token)
85
  return {
86
  "success": True,
87
  "token": self_instance.amaz_token
88
  }
89
- else:
90
  print("No HF_TOKEN found.")
91
  return {
92
  "success": False,
@@ -104,7 +99,6 @@ class AmazonThisObject(ReachyMiniApp):
104
  #Take photo REST POST request
105
  @self.settings_app.post("/take_photo")
106
  def take_photo(self_instance: AmazonThisObject = Depends(self._get_self)):
107
- print("Take a photo")
108
  nonlocal last_photo, last_photo_timestamp
109
 
110
  # Part for the Simulator
@@ -119,12 +113,13 @@ class AmazonThisObject(ReachyMiniApp):
119
  frame = reachy_mini.media.get_frame()
120
  if frame is None:
121
  return {"success": False, "error": "Camera not available"}
 
 
122
 
123
  # Encode as JPEG
124
  success, encoded = cv2.imencode('.jpg', frame, [cv2.IMWRITE_JPEG_QUALITY, 90])
125
  if not success:
126
  return {"success": False, "error": "Failed to encode image"}
127
- print("Encode picture Success")
128
 
129
  #Save last photo
130
  last_photo = encoded.tobytes()
 
29
  image_url = f""
30
  exec_dir = os.path.abspath(__file__)
31
  exec_dir = exec_dir.replace("main.py","")
 
32
  file_path = Path(exec_dir) / ".env"
33
 
34
  @self.settings_app.post("/set_token")
 
43
  "message": "No token provided."
44
  }
45
 
46
+ # Erase or add new file with HF_TOKEN=ton_token
 
 
47
  with open(file_path, "w") as f:
48
  f.write(f"HF_TOKEN={token}\n")
49
  print(f"Token Hugging Face successfully saved in {file_path}")
 
57
  "message": "Error on server side"
58
  }
59
 
60
+ @self.settings_app.post("/check_token")
61
  async def hf_token_available(self_instance: AmazonThisObject = Depends(self._get_self)):
62
+ file_path = Path(exec_dir) / ".env"
63
+ if not file_path.exists():
64
+ return {
65
+ "success": False,
 
66
  "token": None
67
+ }
68
+ try:
69
+ # Read all the file
70
+ with open(file_path, "r", encoding="utf-8") as f:
71
  lines = f.readlines()
72
+ # Find line HF_TOKEN=
73
+ for line in lines:
74
  line = line.strip()
75
  if line.startswith("HF_TOKEN="):
76
  # On prend tout après le =
77
  self_instance.amaz_token = line.split("=", 1)[1].strip().strip('"').strip("'")
78
  break
79
+ if self_instance.amaz_token:
 
80
  return {
81
  "success": True,
82
  "token": self_instance.amaz_token
83
  }
84
+ else:
85
  print("No HF_TOKEN found.")
86
  return {
87
  "success": False,
 
99
  #Take photo REST POST request
100
  @self.settings_app.post("/take_photo")
101
  def take_photo(self_instance: AmazonThisObject = Depends(self._get_self)):
 
102
  nonlocal last_photo, last_photo_timestamp
103
 
104
  # Part for the Simulator
 
113
  frame = reachy_mini.media.get_frame()
114
  if frame is None:
115
  return {"success": False, "error": "Camera not available"}
116
+
117
+ reachy_mini.media.play_sound("wall_E_language/sound/shutter.mp3")
118
 
119
  # Encode as JPEG
120
  success, encoded = cv2.imencode('.jpg', frame, [cv2.IMWRITE_JPEG_QUALITY, 90])
121
  if not success:
122
  return {"success": False, "error": "Failed to encode image"}
 
123
 
124
  #Save last photo
125
  last_photo = encoded.tobytes()
amazon_this_object/static/main.js CHANGED
@@ -12,7 +12,7 @@ let currentFilename = null;
12
  HF_TOKEN = ""
13
 
14
  async function set_token() {
15
- const token_value = hf_token.value.trim(); // On trim au cas où y'aurait des espaces de merde
16
 
17
  if (!token_value) {
18
  console.error("Token part is empty.");
@@ -25,7 +25,7 @@ async function set_token() {
25
  headers: {
26
  'Content-Type': 'application/json'
27
  },
28
- body: JSON.stringify({ token: token_value }) // Voilà, on envoie le token, putain !
29
  });
30
 
31
  const data = await resp.json();
@@ -33,7 +33,6 @@ async function set_token() {
33
  if (data.success) {
34
  main_container.style.display = 'block';
35
  console.log("Token recorded :", data);
36
- // Tu peux ajouter un message à l'UI ici si tu veux
37
  } else {
38
  console.error("Error :", data.message || data);
39
  }
 
12
  HF_TOKEN = ""
13
 
14
  async function set_token() {
15
+ const token_value = hf_token.value.trim();
16
 
17
  if (!token_value) {
18
  console.error("Token part is empty.");
 
25
  headers: {
26
  'Content-Type': 'application/json'
27
  },
28
+ body: JSON.stringify({ token: token_value })
29
  });
30
 
31
  const data = await resp.json();
 
33
  if (data.success) {
34
  main_container.style.display = 'block';
35
  console.log("Token recorded :", data);
 
36
  } else {
37
  console.error("Error :", data.message || data);
38
  }