AgainstEntropy commited on
Commit
dffe42a
β€’
1 Parent(s): 3a60dca

add requirements.txt

Browse files
Files changed (4) hide show
  1. app.py +1 -1
  2. image_utils.py +68 -0
  3. requirements.txt +6 -0
  4. style.css +17 -0
app.py CHANGED
@@ -91,7 +91,7 @@ else:
91
  DESCRIPTION += "\n<p>This demo will get the best kanji streaming experience in localhost (or SSH forward), instead of shared link generated by Gradio.</p>"
92
 
93
  client = InferenceClient(
94
- "mistralai/Mixtral-8x7B-Instruct-v0.1"
95
  )
96
 
97
  def format_prompt(message, history):
 
91
  DESCRIPTION += "\n<p>This demo will get the best kanji streaming experience in localhost (or SSH forward), instead of shared link generated by Gradio.</p>"
92
 
93
  client = InferenceClient(
94
+ model="mistralai/Mixtral-8x7B-Instruct-v0.1",
95
  )
96
 
97
  def format_prompt(message, history):
image_utils.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from PIL import Image
4
+
5
+
6
+ class ImageStitcher:
7
+ def __init__(
8
+ self,
9
+ tmp_dir: str,
10
+ img_res: int = 64,
11
+ img_per_line: int = 10,
12
+ verbose: bool = False
13
+ ):
14
+ self.update_tmp_dir(tmp_dir)
15
+
16
+ self.img_res = img_res if isinstance(img_res, tuple) else (img_res, img_res)
17
+ self.img_per_line = img_per_line
18
+
19
+ self.verbose = verbose
20
+
21
+ self.reset()
22
+
23
+ def reset(self):
24
+ self.cached_img = None
25
+ self.img_num = 0
26
+ self.num_lines = 1
27
+
28
+ self.total_width = self.img_res[0] * self.img_per_line
29
+ self.total_height = self.img_res[1] * self.num_lines
30
+
31
+ def update_tmp_dir(self, tmp_dir: str):
32
+ tmp_dir = os.path.abspath(tmp_dir)
33
+ os.makedirs(tmp_dir, exist_ok=True)
34
+ self.tmp_img_path_template = os.path.join(tmp_dir, "img_%03d.png")
35
+
36
+ def add(self, img: Image, text: str = None):
37
+
38
+ img = img.resize(self.img_res)
39
+
40
+ if self.cached_img is None:
41
+ new_img = Image.new('RGBA', (self.total_width, self.total_height))
42
+ new_img.paste(img, (0, 0))
43
+ else:
44
+ num_lines = self.img_num // self.img_per_line + 1
45
+ if num_lines > self.num_lines:
46
+ self.num_lines = num_lines
47
+ self.total_height = self.img_res[1] * self.num_lines
48
+ new_img = Image.new('RGBA', (self.total_width, self.total_height))
49
+ new_img.paste(self.cached_img, (0, 0))
50
+ elif num_lines == self.num_lines:
51
+ new_img = self.cached_img
52
+
53
+ y_offset = self.img_res[1] * (num_lines - 1)
54
+ x_offset = self.img_res[0] * (self.img_num % self.img_per_line)
55
+ new_img.paste(img, (x_offset, y_offset))
56
+
57
+ save_path = self.tmp_img_path_template % self.img_num
58
+ if text is not None:
59
+ save_path = save_path.replace(".png", f"_{text}.png")
60
+ new_img.save(save_path)
61
+ self.cached_img = new_img
62
+ self.img_num += 1
63
+
64
+ if self.verbose:
65
+ print(f"Saved image to {save_path}")
66
+
67
+ return save_path
68
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ diffusers
3
+ transformers
4
+ pillow
5
+
6
+ StreamDiffusionIO
style.css ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ display: block;
4
+ }
5
+
6
+ #duplicate-button {
7
+ margin: auto;
8
+ color: white;
9
+ background: #1565c0;
10
+ border-radius: 100vh;
11
+ }
12
+
13
+ .contain {
14
+ max-width: 900px;
15
+ margin: auto;
16
+ padding-top: 1.5rem;
17
+ }