[object Object]

← back to Exo

Images stored in system

4b8c4a795fe33f730c294c82d81a8f29046a5009 · 2024-12-01 19:31:51 -0500 · Pranav Veldurthi

Files touched

Diff

commit 4b8c4a795fe33f730c294c82d81a8f29046a5009
Author: Pranav Veldurthi <veldurthipranav@gmail.com>
Date:   Sun Dec 1 19:31:51 2024 -0500

    Images stored in system
---
 exo/api/chatgpt_api.py |  7 ++++---
 exo/helpers.py         | 21 ++++++++++++++++++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/exo/api/chatgpt_api.py b/exo/api/chatgpt_api.py
index af52452d..9ce16381 100644
--- a/exo/api/chatgpt_api.py
+++ b/exo/api/chatgpt_api.py
@@ -13,7 +13,7 @@ import signal
 import sys
 from exo import DEBUG, VERSION
 from exo.download.download_progress import RepoProgressEvent
-from exo.helpers import PrefixDict, shutdown
+from exo.helpers import PrefixDict, shutdown, get_exo_images_dir
 from exo.inference.tokenizers import resolve_tokenizer
 from exo.orchestration import Node
 from exo.models import build_base_shard, model_cards, get_repo, pretty_name, get_supported_models
@@ -184,7 +184,7 @@ class ChatGPTAPI:
       self.static_dir = Path(__file__).parent.parent/"tinychat"
       self.app.router.add_get("/", self.handle_root)
       self.app.router.add_static("/", self.static_dir, name="static")
-      self.app.router.add_static('/images/', self.static_dir / 'images', name='static_images')
+      self.app.router.add_static('/images/', get_exo_images_dir(), name='static_images')
 
     self.app.middlewares.append(self.timeout_middleware)
     self.app.middlewares.append(self.log_request)
@@ -416,9 +416,10 @@ class ChatGPTAPI:
 
           elif isinstance(result, np.ndarray):
             im = Image.fromarray(np.array(result))
+            images_folder = get_exo_images_dir()
             # Save the image to a file
             image_filename = f"{_request_id}.png"
-            image_path = self.static_dir / "images" / image_filename
+            image_path = images_folder / image_filename
             im.save(image_path)
             image_url = request.app.router['static_images'].url_for(filename=image_filename)
             base_url = f"{request.scheme}://{request.host}"
diff --git a/exo/helpers.py b/exo/helpers.py
index 1bba9cd9..ea11bcd9 100644
--- a/exo/helpers.py
+++ b/exo/helpers.py
@@ -252,4 +252,23 @@ async def shutdown(signal, loop, server):
 def is_frozen():
   return getattr(sys, 'frozen', False) or os.path.basename(sys.executable) == "exo" \
     or ('Contents/MacOS' in str(os.path.dirname(sys.executable))) \
-    or '__nuitka__' in globals() or getattr(sys, '__compiled__', False)
\ No newline at end of file
+    or '__nuitka__' in globals() or getattr(sys, '__compiled__', False)
+
+
+def get_exo_home() -> Path:
+  if os.name == "nt":  # Check if the OS is Windows
+    docs_folder = Path(os.environ["USERPROFILE"]) / "Documents"
+  else:
+    docs_folder = Path.home() / "Documents"
+  exo_folder = docs_folder / "Exo"
+  if not exo_folder.exists():
+    exo_folder.mkdir()
+  return exo_folder
+
+def get_exo_images_dir() -> Path:
+  exo_home = get_exo_home()
+  images_dir = exo_home / "Images"
+  if not images_dir.exists():
+    images_dir.mkdir()
+  return images_dir
+  
\ No newline at end of file

← f339f74f trigger test  ·  back to Exo  ·  trigger test 71db641f →