Ciara commited on
Commit
8c65296
1 Parent(s): fdd61f4

Initial Files

Browse files
Files changed (2) hide show
  1. temporalnetv3.ckpt +3 -0
  2. temporalvideo.py +110 -0
temporalnetv3.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a5b9f31f6d7e11aed40da84399c3aeebe7129a9788c0199cfa5d579d9363607
3
+ size 12688107909
temporalvideo.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import requests
4
+ import json
5
+ from pprint import pprint
6
+ import base64
7
+ from io import BytesIO
8
+
9
+
10
+ # Replace with the actual path to your image file and folder
11
+ x_path = "./init.png"
12
+ y_folder = "./New folder"
13
+
14
+ output_folder = "output"
15
+ os.makedirs(output_folder, exist_ok=True)
16
+
17
+ def get_image_paths(folder):
18
+ image_extensions = ("*.jpg", "*.jpeg", "*.png", "*.bmp")
19
+ files = []
20
+ for ext in image_extensions:
21
+ files.extend(glob.glob(os.path.join(folder, ext)))
22
+ return sorted(files)
23
+
24
+ y_paths = get_image_paths(y_folder)
25
+
26
+ def send_request(init_image_path, temp_path,controlnet_input_image_path):
27
+ url = "http://localhost:7860/sdapi/v1/img2img"
28
+
29
+ with open(init_image_path, "rb") as f:
30
+ init_image = base64.b64encode(f.read()).decode("utf-8")
31
+
32
+ with open(controlnet_input_image_path, "rb") as b:
33
+ controlnet_input_image = base64.b64encode(b.read()).decode("utf-8")
34
+
35
+ data = {
36
+ "init_images": [init_image],
37
+ "inpainting_fill": 0,
38
+ "inpaint_full_res": True,
39
+ "inpaint_full_res_padding": 1,
40
+ "inpainting_mask_invert": 1,
41
+ "resize_mode": 0,
42
+ "denoising_strength": 0.5,
43
+ "prompt": "anime man at computer",
44
+ "negative_prompt": "(ugly:1.3), (fused fingers), (too many fingers), (bad anatomy:1.5), (watermark:1.5), (words), letters, untracked eyes, asymmetric eyes, floating head, (logo:1.5), (bad hands:1.3), (mangled hands:1.2), (missing hands), (missing arms), backward hands, floating jewelry, unattached jewelry, floating head, doubled head, unattached head, doubled head, head in body, (misshapen body:1.1), (badly fitted headwear:1.2), floating arms, (too many arms:1.5), limbs fused with body, (facial blemish:1.5), badly fitted clothes, imperfect eyes, untracked eyes, crossed eyes, hair growing from clothes, partial faces, hair not attached to head",
45
+ "alwayson_scripts": {
46
+ "ControlNet":{
47
+ "args": [
48
+ {
49
+ "input_image": controlnet_input_image,
50
+ "module": "hed",
51
+ "model": "control_hed-fp16 [13fee50b]",
52
+ "weight": 1,
53
+ "guidance": 0.6,
54
+ },
55
+ {
56
+ "input_image": init_image,
57
+ "model": "temporalnetv3 [b146ac48]",
58
+ "module": "none",
59
+ "weight": 1,
60
+ "guidance": 0.8,
61
+ }
62
+
63
+ ]
64
+ }
65
+ },
66
+ "seed": 770169050,
67
+ "subseed": -1,
68
+ "subseed_strength": -1,
69
+ "sampler_index": "Euler a",
70
+ "batch_size": 1,
71
+ "n_iter": 1,
72
+ "steps": 20,
73
+ "cfg_scale": 6,
74
+ "width": 1152,
75
+ "height": 640,
76
+ "restore_faces": True,
77
+ "include_init_images": True,
78
+ "override_settings": {},
79
+ "override_settings_restore_afterwards": True
80
+ }
81
+ response = requests.post(url, json=data)
82
+ if response.status_code == 200:
83
+ return response.content
84
+ else:
85
+ try:
86
+ error_data = response.json()
87
+ print("Error:")
88
+ print(str(error_data))
89
+
90
+ except json.JSONDecodeError:
91
+ print(f"Error: Unable to parse JSON error data.")
92
+ return None
93
+
94
+ output_images = []
95
+ output_images.append(send_request(x_path,y_folder, y_paths[0]))
96
+ output_paths = []
97
+
98
+ for i in range(1, len(y_paths)):
99
+ result_image = output_images[i-1]
100
+ temp_image_path = os.path.join(output_folder, f"temp_image_{i}.png")
101
+ data = json.loads(result_image)
102
+ encoded_image = data["images"][0]
103
+ with open(temp_image_path, "wb") as f:
104
+ f.write(base64.b64decode(encoded_image))
105
+ output_paths.append(temp_image_path)
106
+ result = send_request(y_paths[i], y_folder, temp_image_path)
107
+ output_images.append(result)
108
+ print(f"Written data for frame {i}:")
109
+
110
+