Browse Source

Added clear all history button

Sami Khan 7 months ago
parent
commit
0d8a1ee41e
4 changed files with 38 additions and 2 deletions
  1. 2 2
      exo/inference/tinygrad/inference.py
  2. 23 0
      exo/tinychat/index.css
  3. 7 0
      exo/tinychat/index.html
  4. 6 0
      exo/tinychat/index.js

+ 2 - 2
exo/inference/tinygrad/inference.py

@@ -55,7 +55,7 @@ class TinygradDynamicShardInferenceEngine(InferenceEngine):
     self.shard_downloader = shard_downloader
     self.shard_downloader = shard_downloader
     self.executor = ThreadPoolExecutor(max_workers=1)
     self.executor = ThreadPoolExecutor(max_workers=1)
 
 
-  async def infer_prompt(self, request_id: str, shard: Shard, prompt: str, image_str: Optional[str] = None, inference_state: Optional[str] = None) -> (np.ndarray, str, bool):
+  async def infer_prompt(self, request_id: str, shard: Shard, prompt: str, image_str: Optional[str] = None, inference_state: Optional[str] = None) -> tuple[np.ndarray, str, bool]:
     await self.ensure_shard(shard)
     await self.ensure_shard(shard)
     start_pos = json.loads(inference_state or "{}").get("start_pos", 0)
     start_pos = json.loads(inference_state or "{}").get("start_pos", 0)
     n_captured_toks = json.loads(inference_state or "{}").get("n_captured_toks", 0)
     n_captured_toks = json.loads(inference_state or "{}").get("n_captured_toks", 0)
@@ -72,7 +72,7 @@ class TinygradDynamicShardInferenceEngine(InferenceEngine):
       n_captured_toks = len(toks)
       n_captured_toks = len(toks)
       return h.numpy(), json.dumps({"start_pos": start_pos, "n_captured_toks": n_captured_toks}), False
       return h.numpy(), json.dumps({"start_pos": start_pos, "n_captured_toks": n_captured_toks}), False
 
 
-  async def infer_tensor(self, request_id: str, shard: Shard, input_data: np.ndarray, inference_state: Optional[str] = None) -> Tuple[np.ndarray, str, bool]:
+  async def infer_tensor(self, request_id: str, shard: Shard, input_data: np.ndarray, inference_state: Optional[str] = None) -> tuple[np.ndarray, str, bool]:
     await self.ensure_shard(shard)
     await self.ensure_shard(shard)
     start_pos = json.loads(inference_state or "{}").get("start_pos", 0)
     start_pos = json.loads(inference_state or "{}").get("start_pos", 0)
     n_captured_toks = json.loads(inference_state or "{}").get("n_captured_toks", 0)
     n_captured_toks = json.loads(inference_state or "{}").get("n_captured_toks", 0)

+ 23 - 0
exo/tinychat/index.css

@@ -414,4 +414,27 @@ p {
   max-width: 100%;
   max-width: 100%;
   max-height: 100%;
   max-height: 100%;
   object-fit: contain;
   object-fit: contain;
+}
+
+.clear-history-button {
+  background-color: var(--red-color);
+  color: white;
+  padding: 10px 20px;
+  border-radius: 5px;
+  display: flex;
+  align-items: center;
+  gap: 8px;
+  transition: all 0.3s ease;
+  margin: 1rem auto;
+  border: none;
+  cursor: pointer;
+}
+
+.clear-history-button:hover {
+  opacity: 0.8;
+  transform: scale(1.05);
+}
+
+.clear-history-button i {
+  font-size: 14px;
 }
 }

+ 7 - 0
exo/tinychat/index.html

@@ -71,6 +71,13 @@
       if (home === -1) setTimeout(() => home = 0, 100);
       if (home === -1) setTimeout(() => home = 0, 100);
     " x-show="home === 0" x-transition="">
     " x-show="home === 0" x-transition="">
 <h1 class="title megrim-regular">tinychat</h1>
 <h1 class="title megrim-regular">tinychat</h1>
+<template x-if="histories.length">
+  <button 
+    @click="if(confirm('Are you sure you want to clear all history?')) clearAllHistory();" 
+    class="clear-history-button">
+    <i class="fas fa-trash"></i> Clear All History
+  </button>
+</template>
 <div class="histories-container-container">
 <div class="histories-container-container">
 <template x-if="histories.length">
 <template x-if="histories.length">
 <div class="histories-start"></div>
 <div class="histories-start"></div>

+ 6 - 0
exo/tinychat/index.js

@@ -47,6 +47,12 @@ document.addEventListener("alpine:init", () => {
         localStorage.setItem("histories", JSON.stringify(this.histories));
         localStorage.setItem("histories", JSON.stringify(this.histories));
       }
       }
     },
     },
+
+    clearAllHistory() {
+      this.histories = [];
+      localStorage.setItem("histories", JSON.stringify([]));
+    },
+
     // Utility functions
     // Utility functions
     formatBytes(bytes) {
     formatBytes(bytes) {
       if (bytes === 0) return '0 B';
       if (bytes === 0) return '0 B';