Akjava commited on
Commit
a67b1ad
β€’
1 Parent(s): 0ec3640

update example

Browse files
This view is limited to 50 files because it contains too many changes. Β  See raw diff
Files changed (50) hide show
  1. app.py +48 -37
  2. demo_footer.html +3 -0
  3. demo_header.html +18 -2
  4. demo_tools.html +10 -0
  5. {webpes β†’ examples}/00002062.webp +0 -0
  6. {imgs β†’ examples}/00002062_00.jpg +0 -0
  7. {imgs β†’ examples}/00002062_09.jpg +0 -0
  8. {imgs β†’ examples}/00002062_99.jpg +0 -0
  9. {webpes β†’ examples}/00003245.webp +0 -0
  10. {imgs β†’ examples}/00003245_eyes.jpg +0 -0
  11. {imgs β†’ examples}/00003245_mouth.jpg +0 -0
  12. {imgs β†’ examples}/00003245_normal.jpg +0 -0
  13. {webpes β†’ examples}/00100265.webp +0 -0
  14. {imgs β†’ examples}/00100265_00.jpg +0 -0
  15. {imgs β†’ examples}/00100265_09.jpg +0 -0
  16. {imgs β†’ examples}/00100265_99.jpg +0 -0
  17. {webpes β†’ examples}/00207245.webp +0 -0
  18. {imgs β†’ examples}/00207245_eyes.png +0 -0
  19. {imgs β†’ examples}/00207245_mouth.png +0 -0
  20. {imgs β†’ examples}/00207245_normal.png +0 -0
  21. {webpes β†’ examples}/00350245.webp +0 -0
  22. {imgs β†’ examples}/00350245_eyes.jpg +0 -0
  23. {imgs β†’ examples}/00350245_mouth.jpg +0 -0
  24. {imgs β†’ examples}/00350245_normal.jpg +0 -0
  25. {webpes β†’ examples}/00538245.webp +0 -0
  26. {imgs β†’ examples}/00538245_eyes.jpg +0 -0
  27. {imgs β†’ examples}/00538245_mouth.jpg +0 -0
  28. {imgs β†’ examples}/00538245_normal.jpg +0 -0
  29. {webpes β†’ examples}/00824006.webp +0 -0
  30. {imgs β†’ examples}/00824006_00.jpg +0 -0
  31. {imgs β†’ examples}/00824006_09.jpg +0 -0
  32. {imgs β†’ examples}/00824006_99.jpg +0 -0
  33. {webpes β†’ examples}/00824008.webp +0 -0
  34. {imgs β†’ examples}/00824008_00.jpg +0 -0
  35. {imgs β†’ examples}/00824008_09.jpg +0 -0
  36. {imgs β†’ examples}/00824008_99.jpg +0 -0
  37. {webpes β†’ examples}/00825000.webp +0 -0
  38. {imgs β†’ examples}/00825000_00.jpg +0 -0
  39. {imgs β†’ examples}/00825000_09.jpg +0 -0
  40. {imgs β†’ examples}/00825000_99.jpg +0 -0
  41. {webpes β†’ examples}/00826004.webp +0 -0
  42. {imgs β†’ examples}/00826004_00.jpg +0 -0
  43. {imgs β†’ examples}/00826004_09.jpg +0 -0
  44. {imgs β†’ examples}/00826004_99.jpg +0 -0
  45. {webpes β†’ examples}/00826007.webp +0 -0
  46. {imgs β†’ examples}/00826007_00.jpg +0 -0
  47. {imgs β†’ examples}/00826007_09.jpg +0 -0
  48. {imgs β†’ examples}/00826007_99.jpg +0 -0
  49. {webpes β†’ examples}/00827009.webp +0 -0
  50. {imgs β†’ examples}/00827009_00.jpg +0 -0
app.py CHANGED
@@ -8,6 +8,7 @@ import io
8
  import hashlib
9
  import os
10
  import time
 
11
  css="""
12
  #col-left {
13
  margin: 0 auto;
@@ -17,10 +18,27 @@ css="""
17
  margin: 0 auto;
18
  max-width: 640px;
19
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  """
21
 
 
22
  output_dir = "outputs"
23
- passed_time = 60 #* 60
24
  def load_text(text_path: str) -> str:
25
  with open(text_path, 'r', encoding='utf-8') as f:
26
  text = f.read()
@@ -28,17 +46,19 @@ def load_text(text_path: str) -> str:
28
  return text
29
 
30
  def clear_old_files(dir,passed_time):
31
- files = os.listdir(dir)
32
- current_time = time.time()
33
- for file in files:
34
- file_path = os.path.join(dir,file)
35
- #print(os.stat(file_path))
36
- ctime = os.stat(file_path).st_ctime
37
- diff = current_time - ctime
38
- print(f"ctime={ctime},current_time={current_time},passed_time={passed_time},diff={diff}")
39
- if diff > passed_time:
40
- os.remove(file_path)
41
- print(f"file removed {file_path}")
 
 
42
 
43
 
44
  def process_images(normal_image,mouth_open_image,eye_close_image,duration=100,pattern = "nnnmmmnenmmmnnnmmmnnnmmmnnnmmm",looping = True):
@@ -74,11 +94,6 @@ def process_images(normal_image,mouth_open_image,eye_close_image,duration=100,pa
74
  else:
75
  frames.append(normal_image)
76
 
77
- #img = webp.load_image('00044063.webp', 'RGB')
78
- #imgs = webp.load_images('00044063.webp', 'RGB',fps=10)#some how only fps10 load correctly?
79
- #print(len(imgs))
80
-
81
- #print(len(frames))
82
  loop = 0 if looping else 1 #MUST BE ZERO,NOT TRUE
83
  output_path = "tmp.webp"
84
  output_buffer = io.BytesIO()
@@ -106,10 +121,11 @@ def show_example(value1,value2,valu3,id):
106
  return f"webpes/{id}.webp"
107
 
108
  #css=css,
109
- demo_blocks = gr.Blocks(css=css, elem_id="demo-container")
110
- with demo_blocks as demo:
111
  with gr.Column():
112
  gr.HTML(load_text("demo_header.html"))
 
113
  with gr.Row():
114
  with gr.Column():
115
  image_normal = gr.Image(sources=['upload','clipboard'], elem_id="image_normal", type="pil", label="Normal Image",height=400, value=None)
@@ -131,26 +147,21 @@ with demo_blocks as demo:
131
  btn.click(fn=process_images, inputs=[image_normal, image_mouth,image_eyes,animation_time,timing_seat,looping], outputs =image_out, api_name='infer')
132
  gr.Examples(
133
  examples=[
134
- ["imgs/00003245_normal.jpg","imgs/00003245_mouth.jpg","imgs/00003245_eyes.jpg","00003245"],
135
- ["imgs/00207245_normal.png","imgs/00207245_mouth.png","imgs/00207245_eyes.png","00207245"],
136
- ["imgs/00350245_normal.jpg","imgs/00350245_mouth.jpg","imgs/00350245_eyes.jpg","00350245"],
137
- ["imgs/00538245_normal.jpg","imgs/00538245_mouth.jpg","imgs/00538245_eyes.jpg","00538245"],
138
- ["imgs/00828003_00.jpg","imgs/00828003_09.jpg","imgs/00828003_99.jpg","00828003"],
139
- ["imgs/00825000_00.jpg","imgs/00825000_09.jpg","imgs/00825000_99.jpg","00825000"],
140
- ["imgs/00824008_00.jpg","imgs/00824008_09.jpg","imgs/00824008_99.jpg","00824008"],
141
- ["imgs/prompt01_normal.jpg","imgs/prompt01_mouth.jpg","imgs/prompt01_eyes.jpg","prompt01"],
142
  ],
143
- fn=show_example,
144
- inputs=[image_normal,image_mouth,image_eyes,id_input],outputs=[image_out],
145
- cache_examples=True,
146
  )
147
  gr.HTML(
148
- """
149
- <div style="text-align: center;">
150
- <p>Test <a href="http://google.com" style="text-decoration: underline;" target="_blank">Google</a> - Gradio Demo by πŸ€— Hugging Face
151
- </p>
152
- </div>
153
- """
154
  )
155
 
156
- demo_blocks.queue(max_size=25).launch()#share=True
 
 
8
  import hashlib
9
  import os
10
  import time
11
+ import shutil
12
  css="""
13
  #col-left {
14
  margin: 0 auto;
 
18
  margin: 0 auto;
19
  max-width: 640px;
20
  }
21
+ .grid-container {
22
+ display: flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+ gap:10px
26
+ }
27
+
28
+ .image {
29
+ width: 128px;
30
+ height: 128px;
31
+ object-fit: cover;
32
+ }
33
+
34
+ .text {
35
+ font-size: 16px;
36
+ }
37
  """
38
 
39
+
40
  output_dir = "outputs"
41
+ passed_time = 60 * 10
42
  def load_text(text_path: str) -> str:
43
  with open(text_path, 'r', encoding='utf-8') as f:
44
  text = f.read()
 
46
  return text
47
 
48
  def clear_old_files(dir,passed_time):
49
+ try:
50
+ files = os.listdir(dir)
51
+ current_time = time.time()
52
+ for file in files:
53
+ file_path = os.path.join(dir,file)
54
+
55
+ ctime = os.stat(file_path).st_ctime
56
+ diff = current_time - ctime
57
+ #print(f"ctime={ctime},current_time={current_time},passed_time={passed_time},diff={diff}")
58
+ if diff > passed_time:
59
+ os.remove(file_path)
60
+ except:
61
+ print("maybe still gallery using error")
62
 
63
 
64
  def process_images(normal_image,mouth_open_image,eye_close_image,duration=100,pattern = "nnnmmmnenmmmnnnmmmnnnmmmnnnmmm",looping = True):
 
94
  else:
95
  frames.append(normal_image)
96
 
 
 
 
 
 
97
  loop = 0 if looping else 1 #MUST BE ZERO,NOT TRUE
98
  output_path = "tmp.webp"
99
  output_buffer = io.BytesIO()
 
121
  return f"webpes/{id}.webp"
122
 
123
  #css=css,
124
+
125
+ with gr.Blocks(css=css, elem_id="demo-container") as demo:
126
  with gr.Column():
127
  gr.HTML(load_text("demo_header.html"))
128
+ gr.HTML(load_text("demo_tools.html"))
129
  with gr.Row():
130
  with gr.Column():
131
  image_normal = gr.Image(sources=['upload','clipboard'], elem_id="image_normal", type="pil", label="Normal Image",height=400, value=None)
 
147
  btn.click(fn=process_images, inputs=[image_normal, image_mouth,image_eyes,animation_time,timing_seat,looping], outputs =image_out, api_name='infer')
148
  gr.Examples(
149
  examples=[
150
+ ["examples/00003245_normal.jpg","examples/00003245_mouth.jpg","examples/00003245_eyes.jpg","examples/00003245.webp"],
151
+ ["examples/00207245_normal.png","examples/00207245_mouth.png","examples/00207245_eyes.png","examples/00207245.webp"],
152
+ ["examples/00350245_normal.jpg","examples/00350245_mouth.jpg","examples/00350245_eyes.jpg","examples/00350245.webp"],
153
+ ["examples/00538245_normal.jpg","examples/00538245_mouth.jpg","examples/00538245_eyes.jpg","examples/00538245.webp"],
154
+ ["examples/00828003_00.jpg","examples/00828003_09.jpg","examples/00828003_99.jpg","examples/00828003.webp"],
155
+ ["examples/00825000_00.jpg","examples/00825000_09.jpg","examples/00825000_99.jpg","examples/00825000.webp"],
156
+ ["examples/00824008_00.jpg","examples/00824008_09.jpg","examples/00824008_99.jpg","examples/00824008.webp"],
157
+ ["examples/prompt01_normal.jpg","examples/prompt01_mouth.jpg","examples/prompt01_eyes.jpg","examples/prompt01.webp"],
158
  ],
159
+ inputs=[image_normal,image_mouth,image_eyes,image_out],
160
+
 
161
  )
162
  gr.HTML(
163
+ gr.HTML(load_text("demo_footer.html"))
 
 
 
 
 
164
  )
165
 
166
+ if __name__ == "__main__":
167
+ demo.launch()
demo_footer.html ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ <div>
2
+ <P> Images are generated with <a href="https://huggingface.co/black-forest-labs/FLUX.1-schnell">FLUX.1-schnell</a> and licensed under <a href="http://www.apache.org/licenses/LICENSE-2.0">the Apache 2.0 License</a>
3
+ </div>
demo_header.html CHANGED
@@ -1,2 +1,18 @@
1
- <h1>WebP 3-Frame TalkingAnimation</h1>
2
- <p>This is Character Face part of AI Diagram Chat with Voice/Face Character</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center;">
2
+ <h1>
3
+ WebP 3-Frame TalkingAnimation
4
+ </h1>
5
+ <div class="grid-container">
6
+ <img src="https://akjava.github.io/AIDiagramChatWithVoice-FaceCharacter/webp/128/00346245_09_00001200.webp" alt="Flux.1-schnell-WebP3Frame-TalkingAnimation" class="image">
7
+ <p class="text">
8
+ Create animation from 3 frame images<br>
9
+ Main create tool is not relaeased yet(mediapipe68-based and img2img-based)<br>
10
+ however you can create from prompt like eyes closed and open mouth.one of example is made by this way<br>
11
+ created webp can be resize and convert with tool.
12
+ </p>
13
+ </div>
14
+ </div>
15
+
16
+
17
+
18
+ <h1></h1>
demo_tools.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center;">
2
+ <p><a href="https://huggingface.co/spaces/Akjava/AIDiagramChatWithVoice-FaceCharacter">AI Diagram Chat with Voice/Face Character Making Tools</a></p>
3
+ <p><a href="https://huggingface.co/spaces/Akjava/WebPTalkHead">[WebP-3F-TH]</a>
4
+ <a href="https://huggingface.co/spaces/Akjava/flux1-schnell-img2img">[Flux1-Img2Img(GPU)]</a>
5
+ <a href="https://huggingface.co/spaces/Akjava/flux1-schnell-mask-inpaint">[Flux1-Inpaint(GPU)]</a>
6
+ <a href="https://huggingface.co/spaces/Akjava/OpenCVInpaintCPU">[OpenCV-Inapint]</a>
7
+ <a href="https://huggingface.co/spaces/Akjava/Simple-Whitebalance-Image">[Whitebalance]</a>
8
+ <a href="https://huggingface.co/spaces/Akjava/Simple-Mask-Paste-Image">[Paste Image]</a>
9
+ <a href=" https://huggingface.co/spaces/Akjava/WebP-Resize-Convert">[WebP Resize Convert]</a></p>
10
+ </div>
{webpes β†’ examples}/00002062.webp RENAMED
File without changes
{imgs β†’ examples}/00002062_00.jpg RENAMED
File without changes
{imgs β†’ examples}/00002062_09.jpg RENAMED
File without changes
{imgs β†’ examples}/00002062_99.jpg RENAMED
File without changes
{webpes β†’ examples}/00003245.webp RENAMED
File without changes
{imgs β†’ examples}/00003245_eyes.jpg RENAMED
File without changes
{imgs β†’ examples}/00003245_mouth.jpg RENAMED
File without changes
{imgs β†’ examples}/00003245_normal.jpg RENAMED
File without changes
{webpes β†’ examples}/00100265.webp RENAMED
File without changes
{imgs β†’ examples}/00100265_00.jpg RENAMED
File without changes
{imgs β†’ examples}/00100265_09.jpg RENAMED
File without changes
{imgs β†’ examples}/00100265_99.jpg RENAMED
File without changes
{webpes β†’ examples}/00207245.webp RENAMED
File without changes
{imgs β†’ examples}/00207245_eyes.png RENAMED
File without changes
{imgs β†’ examples}/00207245_mouth.png RENAMED
File without changes
{imgs β†’ examples}/00207245_normal.png RENAMED
File without changes
{webpes β†’ examples}/00350245.webp RENAMED
File without changes
{imgs β†’ examples}/00350245_eyes.jpg RENAMED
File without changes
{imgs β†’ examples}/00350245_mouth.jpg RENAMED
File without changes
{imgs β†’ examples}/00350245_normal.jpg RENAMED
File without changes
{webpes β†’ examples}/00538245.webp RENAMED
File without changes
{imgs β†’ examples}/00538245_eyes.jpg RENAMED
File without changes
{imgs β†’ examples}/00538245_mouth.jpg RENAMED
File without changes
{imgs β†’ examples}/00538245_normal.jpg RENAMED
File without changes
{webpes β†’ examples}/00824006.webp RENAMED
File without changes
{imgs β†’ examples}/00824006_00.jpg RENAMED
File without changes
{imgs β†’ examples}/00824006_09.jpg RENAMED
File without changes
{imgs β†’ examples}/00824006_99.jpg RENAMED
File without changes
{webpes β†’ examples}/00824008.webp RENAMED
File without changes
{imgs β†’ examples}/00824008_00.jpg RENAMED
File without changes
{imgs β†’ examples}/00824008_09.jpg RENAMED
File without changes
{imgs β†’ examples}/00824008_99.jpg RENAMED
File without changes
{webpes β†’ examples}/00825000.webp RENAMED
File without changes
{imgs β†’ examples}/00825000_00.jpg RENAMED
File without changes
{imgs β†’ examples}/00825000_09.jpg RENAMED
File without changes
{imgs β†’ examples}/00825000_99.jpg RENAMED
File without changes
{webpes β†’ examples}/00826004.webp RENAMED
File without changes
{imgs β†’ examples}/00826004_00.jpg RENAMED
File without changes
{imgs β†’ examples}/00826004_09.jpg RENAMED
File without changes
{imgs β†’ examples}/00826004_99.jpg RENAMED
File without changes
{webpes β†’ examples}/00826007.webp RENAMED
File without changes
{imgs β†’ examples}/00826007_00.jpg RENAMED
File without changes
{imgs β†’ examples}/00826007_09.jpg RENAMED
File without changes
{imgs β†’ examples}/00826007_99.jpg RENAMED
File without changes
{webpes β†’ examples}/00827009.webp RENAMED
File without changes
{imgs β†’ examples}/00827009_00.jpg RENAMED
File without changes