فهرست منبع

Images stored in system

Pranav Veldurthi 5 ماه پیش
والد
کامیت
4b8c4a795f
2فایلهای تغییر یافته به همراه24 افزوده شده و 4 حذف شده
  1. 4 3
      exo/api/chatgpt_api.py
  2. 20 1
      exo/helpers.py

+ 4 - 3
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}"

+ 20 - 1
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)
+    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
+