Kun1009 commited on
Commit
a5b9369
·
verified ·
1 Parent(s): c5f7645

Upload 86 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
.gitattributes CHANGED
@@ -44,3 +44,14 @@ poetry3d/obj/20240827_223159.glb filter=lfs diff=lfs merge=lfs -text
44
  poetry3d/obj/20240828_192708.glb filter=lfs diff=lfs merge=lfs -text
45
  poetry3d/obj/20240828_201959.glb filter=lfs diff=lfs merge=lfs -text
46
  poetry3d/obj/20240829_125414.glb filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
44
  poetry3d/obj/20240828_192708.glb filter=lfs diff=lfs merge=lfs -text
45
  poetry3d/obj/20240828_201959.glb filter=lfs diff=lfs merge=lfs -text
46
  poetry3d/obj/20240829_125414.glb filter=lfs diff=lfs merge=lfs -text
47
+ image/20240828_162621.png filter=lfs diff=lfs merge=lfs -text
48
+ long.png filter=lfs diff=lfs merge=lfs -text
49
+ m1.glb filter=lfs diff=lfs merge=lfs -text
50
+ obj/20240811_015338.glb filter=lfs diff=lfs merge=lfs -text
51
+ obj/20240827_171959.glb filter=lfs diff=lfs merge=lfs -text
52
+ obj/20240827_211152.glb filter=lfs diff=lfs merge=lfs -text
53
+ obj/20240827_214214.glb filter=lfs diff=lfs merge=lfs -text
54
+ obj/20240827_223159.glb filter=lfs diff=lfs merge=lfs -text
55
+ obj/20240828_192708.glb filter=lfs diff=lfs merge=lfs -text
56
+ obj/20240828_201959.glb filter=lfs diff=lfs merge=lfs -text
57
+ obj/20240829_125414.glb filter=lfs diff=lfs merge=lfs -text
2img.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ import torch
5
+ import time
6
+ import cv2
7
+
8
+ def fake_diffusion(prompt):
9
+ # image = np.ones((1000,1000,3), np.uint8)
10
+ # image[:] = [255, 124, 0]
11
+ image=cv2.imread('/home/kun/code/3d/poetry3d/mountain_1.png')
12
+ yield image
13
+
14
+ examples = [
15
+ "千山鸟飞绝,万径人踪灭。孤舟蓑笠翁,独钓寒江雪。【柳宗元 | 江雪】",
16
+ "空山新雨后,天气晚来秋。明月松间照,清泉石上流。【王维 | 山居秋暝】",
17
+ "白日依山尽,黄河入海流。欲穷千里目,更上一层楼。【王之涣 | 登鹳雀楼】",
18
+ "春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少。【孟浩然 | 春晓】"
19
+ ]
20
+
21
+ css="""
22
+ #col-container {
23
+ margin: 0 auto;
24
+ max-width: 520px;
25
+ }
26
+ """
27
+
28
+ if torch.cuda.is_available():
29
+ power_device = "GPU"
30
+ else:
31
+ power_device = "CPU"
32
+
33
+ with gr.Blocks(css=css) as demo:
34
+
35
+ with gr.Column(elem_id="col-container"):
36
+ gr.Markdown(f"""
37
+ # Poetry3D
38
+ Currently running on {power_device}.
39
+ """)
40
+
41
+ with gr.Row():
42
+
43
+ prompt = gr.Text(
44
+ label="Prompt",
45
+ show_label=False,
46
+ max_lines=1,
47
+ placeholder="Enter your prompt",
48
+ container=False,
49
+ )
50
+
51
+ run_button = gr.Button("Run", scale=0)
52
+
53
+ result = gr.Image(label="Result", show_label=False)
54
+
55
+ gr.Examples(
56
+ examples = examples,
57
+ inputs = [prompt]
58
+ )
59
+
60
+ run_button.click(
61
+ fn = fake_diffusion,
62
+ inputs = [prompt],
63
+ outputs = [result]
64
+ )
65
+
66
+ demo.launch()
3d.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+
5
+ def load_mesh(image):
6
+ return mesh_file_name
7
+
8
+
9
+ demo = gr.Interface(
10
+ fn=load_mesh,
11
+ inputs=gr.Model3D(),
12
+ outputs=gr.Model3D(
13
+ clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model"),
14
+ examples=[
15
+ ['/home/kun/code/3d/poetry3d/m1.glb'],
16
+ ],
17
+ )
18
+
19
+ if __name__ == "__main__":
20
+ demo.launch()
README.md CHANGED
@@ -1,12 +1 @@
1
- ---
2
- title: PoeticLandscapes
3
- emoji: 👁
4
- colorFrom: indigo
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 4.44.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # poetry3d
 
 
 
 
 
 
 
 
 
 
 
demo.py ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import numpy as np
3
+ from datetime import datetime
4
+ import cv2
5
+ import random
6
+ import torch
7
+ import time
8
+ from requests.exceptions import ConnectionError, Timeout
9
+ import requests
10
+ import json
11
+ import gradio as gr
12
+ import os
13
+
14
+ def flip_text(x):
15
+ return x[::-1]
16
+
17
+ def flip_image(x):
18
+ return np.fliplr(x)
19
+
20
+ def meshy(img_url):
21
+ #YOUR_API_KEY = 'msy_4aO4tF1js0Xsw0Vo3jdLNgh84NLvZrjo8XjQ'
22
+ YOUR_API_KEY = 'msy_4sAvBmtnJw3PSTWCKaLlFTdPCtcnU2heNZHH'
23
+
24
+ headers = {
25
+ "Authorization": f"Bearer {YOUR_API_KEY}",
26
+ "Content-Type": "application/json"
27
+ }
28
+
29
+ payload = {
30
+ "image_url": img_url, # 替换为实际图片URL
31
+ "enable_pbr": False, # 可选,是否生成 PBR 贴图
32
+ }
33
+ task_id='019192dc-54a7-7621-afae-da16e77b7660'
34
+ '''ID已知'''
35
+ # response = requests.post(
36
+ # "https://api.meshy.ai/v1/image-to-3d",
37
+ # headers=headers,
38
+ # json=payload
39
+ # )
40
+ max_retries = 5
41
+ retry_delay = 1 # 每次重试间隔的秒数
42
+ for attempt in range(max_retries):
43
+ try:
44
+ # 尝试发送请求
45
+ response = requests.post(
46
+ "https://api.meshy.ai/v1/image-to-3d",
47
+ headers=headers,
48
+ json=payload
49
+ )
50
+ print(f"请求状态: {response.status_code}")
51
+ #print(f"任务创建失败,错误信息: {response.text}")
52
+ data = response.json()
53
+ print(data)
54
+ task_id = data['result']
55
+ print(f"任务创建成功,任务 ID: {task_id}")
56
+ break
57
+ except (ConnectionError, Timeout) as e:
58
+ print(f"网络连接失败,正在重试 {attempt + 1}/{max_retries}...")
59
+ print(f"错误信息: {e}")
60
+ time.sleep(retry_delay)
61
+ except requests.exceptions.RequestException as e:
62
+ print(f"请求失败: {e}")
63
+ break # 如果是其他类型的请求错误,不再重试,直接退出
64
+
65
+ # # 检查请求状态
66
+ # print(f"请求状态: {response.status_code}")
67
+ # #print(f"任务创建失败,错误信息: {response.text}")
68
+ # data = response.json()
69
+ # print(data)
70
+ # task_id = data['result']
71
+ # print(f"任务创建成功,任务 ID: {task_id}")
72
+ ''''''
73
+ #task_id='01913d5e-f092-7b44-89f2-922406cc3691'
74
+ # 检索任务状态和结果
75
+ while True:
76
+ try:
77
+ response = requests.get(
78
+ f"https://api.meshy.ai/v1/image-to-3d/{task_id}",
79
+ headers=headers,
80
+ verify=False
81
+ )
82
+ response.raise_for_status() # 检查HTTP请求状态码
83
+ data = response.json()
84
+ status=data['status']
85
+ print(f"任务状态: {status}")
86
+ if status == 'SUCCEEDED':
87
+ download_url = data['model_url']
88
+ print(f"任务完成,3D 模型下载链接: {download_url}")
89
+ response = requests.get(download_url,verify=False)
90
+ return response
91
+ elif status == 'FAILED':
92
+ print("任务失败!")
93
+ return None
94
+ elif status == 'IN_PROGRESS':
95
+ print(f"任务正在处理中,进度:{data['progress']}/100")
96
+ time.sleep(2) # 等待5秒钟后再次检查状态
97
+ # else:
98
+ # print(f"未知状态: {status}")
99
+ # return None
100
+ # download_url = data['model_url']
101
+ # print(f"任务完成,3D 模型下载链接: {download_url}")
102
+ # response = requests.get(download_url,verify=False)
103
+ # return response
104
+ except (ConnectionError, Timeout) as e:
105
+ print("网络连接失败,正在重试")
106
+ print(f"错误信息: {e}")
107
+ time.sleep(1)
108
+ except requests.exceptions.RequestException as e:
109
+ print(f"请求失败: {e}")
110
+ return None
111
+
112
+ # # 检查请求状态
113
+ # print(f"请求状态: {response.status_code}")
114
+ # #print(f"任务查询失败,错误信息: {response.text}")
115
+ # data = response.json()
116
+ # while(data['status'] != 'SUCCEEDED'):
117
+ # time.sleep(2)
118
+ # print(f"任务状态: {data['status']}")
119
+ # data = response.json()
120
+ # download_url = data['model_url']
121
+ # print(f"任务完成,3D 模型下载链接: {download_url}")
122
+ # response = requests.get(download_url,verify=False)
123
+ # return response
124
+
125
+ def upload(path):
126
+ #headers = {'Authorization': 'YxKXccVDyLPhodqaDg4BIYNeJXSuCbkX'}
127
+ headers = {'Authorization': 'XCcVgVPNgTU4PdDOnRKTHraGTze4LHUB'}
128
+ files = {'smfile': open(path, 'rb')}
129
+ url = 'https://sm.ms/api/v2/upload'
130
+ max_retries = 20
131
+ retry_delay = 1 # 每次重试间隔的秒数
132
+ for attempt in range(max_retries):
133
+ try:
134
+ # 尝试发送请求
135
+ res = requests.post(url, files=files, headers=headers,timeout=30)
136
+ res.raise_for_status()
137
+ response_data = res.json()
138
+ print(response_data)
139
+ if response_data.get('success'):
140
+ img_url=res.json()['data']['url']
141
+ print("请求成功,图片URL为:",img_url)
142
+ return img_url
143
+ elif response_data.get('code') == 'image_repeated':
144
+ print("图片重复上传,已存在的图片URL为:", response_data['images'])
145
+ return response_data['images']
146
+ except (ConnectionError, Timeout) as e:
147
+ print(f"网络连接失败,正在重试 {attempt + 1}/{max_retries}...")
148
+ print(f"错误信息: {e}")
149
+ time.sleep(retry_delay)
150
+ except requests.exceptions.RequestException as e:
151
+ print(f"请求失败: {e},code:{response_data.get('code')},message:{response_data.get('message')}")
152
+ time.sleep(retry_delay)
153
+ '''ID已知'''
154
+ # res = requests.post(url, files=files, headers=headers,timeout=30).json()
155
+ # img_url=res['data']['url']
156
+ ''''''
157
+ #img_url=5
158
+ print("未得到url")
159
+ return 'https://s2.loli.net/2024/08/27/HAmJRGznS3ldvrI.png'
160
+
161
+ def gen3d(image):
162
+ #print(image.shape)
163
+ #print(image.type)
164
+ #image = Image.fromarray(np.uint8(image))
165
+ current_time = datetime.now()
166
+ file_name = current_time.strftime("%Y%m%d_%H%M%S") + ".png"
167
+ current_directory = os.getcwd()
168
+ file_path = os.path.join(current_directory, 'image',file_name)
169
+ #print(file_path)
170
+ image = image[:, :, [2,1,0]]
171
+ cv2.imwrite(file_path, image)
172
+ #image.save(file_path)
173
+ #print(success)u
174
+ img_url=upload(file_path)
175
+ response=meshy(img_url)
176
+ file_name = file_name.replace(".png", ".glb")
177
+ file_path = os.path.join(current_directory, 'obj',file_name)
178
+ with open(file_path, "wb") as file:
179
+ file.write(response.content)
180
+ return file_path
181
+
182
+ def predict(im):
183
+ return im["composite"]
184
+
185
+ def display_images():
186
+ img_dir='/home/kun/code/3d/poetry3d/image'
187
+ imgs_List=[ os.path.join(img_dir,name)
188
+ for name in sorted(os.listdir(img_dir))
189
+ if name.endswith(('.png','.jpg','.webp','.tif','.jpeg'))]
190
+ return imgs_List
191
+
192
+ def display_models():
193
+ model_dir='/home/kun/code/3d/poetry3d/obj'
194
+ models_List=[ os.path.join(model_dir,name)
195
+ for name in sorted(os.listdir(model_dir))
196
+ if name.endswith(('.glb'))]
197
+ return models_List[0]
198
+
199
+ def fake_diffusion(prompt):
200
+ # image = np.ones((1000,1000,3), np.uint8)
201
+ # image[:] = [255, 124, 0]
202
+ time.sleep(1)
203
+ image=cv2.imread('/home/kun/code/3d/poetry3d/long.png')
204
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
205
+ yield image
206
+
207
+ poetry_examples = [
208
+ "千山鸟飞绝,万径人踪灭。孤舟蓑笠翁,独钓寒江雪。【柳宗元 | 江雪】",
209
+ "空山新雨后,天气晚来秋。明月松间照,清泉石上流。【王维 | 山居秋暝】",
210
+ "白日依山尽,黄河入海流。欲穷千里目,更上一层楼。【王之涣 | 登鹳雀楼】",
211
+ "春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少。【孟浩然 | 春晓】"
212
+ ]
213
+
214
+ css="""
215
+ #col-container {
216
+ margin: 0 auto;
217
+ max-width: 520px;
218
+ }
219
+ """
220
+ js_func = """
221
+ function refresh() {
222
+ const url = new URL(window.location);
223
+
224
+ if (url.searchParams.get('__theme') !== 'dark') {
225
+ url.searchParams.set('__theme', 'dark');
226
+ window.location.href = url.href;
227
+ }
228
+ }
229
+ """
230
+
231
+ if torch.cuda.is_available():
232
+ power_device = "GPU"
233
+ else:
234
+ power_device = "CPU"
235
+
236
+ with gr.Blocks(css=css,js=js_func,fill_width=True) as demo:
237
+ with gr.Row():
238
+ with gr.Column(elem_id="col-container",scale=20):
239
+ gr.Markdown(f"""
240
+ # Poetic Landscapes
241
+ Currently running on {power_device}.
242
+ """)
243
+
244
+ with gr.Row():
245
+
246
+ prompt = gr.Text(
247
+ label="Prompt",
248
+ show_label=False,
249
+ max_lines=1,
250
+ #placeholder="Enter your prompt",
251
+ placeholder="输入诗句",
252
+ container=False,
253
+ )
254
+
255
+ run_button = gr.Button("生成图像", scale=1)
256
+
257
+ result = gr.Image(label="Result", show_label=False)
258
+
259
+ gr.Examples(
260
+ label="示例诗句",
261
+ examples = poetry_examples,
262
+ inputs = [prompt]
263
+ )
264
+
265
+ # with gr.Row():
266
+ # im = gr.ImageEditor()
267
+ # im_preview = gr.Image()
268
+ im = gr.ImageEditor(label="编辑图像",
269
+ #placeholder="将上一步生成图像拖到此处",
270
+ )
271
+
272
+
273
+
274
+ im_result=gr.Image(label="图像预览",scale=10)
275
+ run_button_2 = gr.Button("生���模型")
276
+
277
+ with gr.Column(scale=10):
278
+ model=gr.Model3D(label="模型",scale=10)
279
+
280
+ with gr.Column(scale=2):
281
+ gallery=gr.Gallery(label="历史图像")
282
+ btn = gr.Button("刷新")
283
+ btn.click(display_images, None, gallery)
284
+ model2=gr.Model3D(label="历史模型",scale=10)
285
+ btn2 = gr.Button("刷新")
286
+ btn2.click(display_models, None, model2)
287
+
288
+ # with gr.Tab("历史图像"):
289
+ # gallery=gr.Gallery(show_label=False)
290
+ # btn = gr.Button("刷新")
291
+ # btn.click(display_images, None, gallery)
292
+ # with gr.Tab("历史模型"):
293
+ # with gr.Row():
294
+ # # model1=gr.Model3D(label="模型")
295
+ # model2=gr.Model3D(label="模型")
296
+ # # model3=gr.Model3D(label="模型")
297
+ # # model4=gr.Model3D(label="模型")
298
+ # btn = gr.Button("刷新")
299
+ # btn.click(display_models, None, model2)
300
+
301
+ run_button.click(
302
+ fn = fake_diffusion,
303
+ inputs = [prompt],
304
+ outputs = [result]
305
+ )
306
+ run_button_2.click(
307
+ fn = gen3d,
308
+ inputs = im_result,
309
+ outputs = model
310
+ )
311
+
312
+
313
+
314
+ # with gr.Column():
315
+ # gr.Interface(
316
+ # fn=gen3d,
317
+ # inputs=gr.Image(),
318
+ # outputs=gr.Model3D(label="3D Model")
319
+ # )
320
+ im.change(predict, outputs=im_result, inputs=im, show_progress="hidden")
321
+
322
+ if __name__ == "__main__":
323
+ demo.launch(share=True)
diffusion.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ from diffusers import DiffusionPipeline
5
+ import torch
6
+ import time
7
+
8
+ # device = "cuda" if torch.cuda.is_available() else "cpu"
9
+
10
+ # if torch.cuda.is_available():
11
+ # torch.cuda.max_memory_allocated(device=device)
12
+ # pipe = DiffusionPipeline.from_pretrained("/home/kun/code/3d", torch_dtype=torch.float16)
13
+ # #pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
14
+ # pipe.enable_xformers_memory_efficient_attention()
15
+ # pipe = pipe.to(device)
16
+ # else:
17
+ # pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
18
+ # pipe = pipe.to(device)
19
+
20
+ MAX_SEED = np.iinfo(np.int32).max
21
+ MAX_IMAGE_SIZE = 1024
22
+
23
+ def fake_diffusion(steps):
24
+ image = np.ones((1000,1000,3), np.uint8)
25
+ image[:] = [255, 124, 0]
26
+ yield image
27
+
28
+ # def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
29
+
30
+ # if randomize_seed:
31
+ # seed = random.randint(0, MAX_SEED)
32
+
33
+ # generator = torch.Generator().manual_seed(seed)
34
+
35
+ # image = pipe(
36
+ # prompt = prompt,
37
+ # negative_prompt = negative_prompt,
38
+ # guidance_scale = guidance_scale,
39
+ # num_inference_steps = num_inference_steps,
40
+ # width = width,
41
+ # height = height,
42
+ # generator = generator
43
+ # ).images[0]
44
+
45
+ # return image
46
+
47
+ examples = [
48
+ "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
49
+ "An astronaut riding a green horse",
50
+ "A delicious ceviche cheesecake slice",
51
+ ]
52
+
53
+ css="""
54
+ #col-container {
55
+ margin: 0 auto;
56
+ max-width: 520px;
57
+ }
58
+ """
59
+
60
+ if torch.cuda.is_available():
61
+ power_device = "GPU"
62
+ else:
63
+ power_device = "CPU"
64
+
65
+ with gr.Blocks(css=css) as demo:
66
+
67
+ with gr.Column(elem_id="col-container"):
68
+ gr.Markdown(f"""
69
+ # Text-to-Image Gradio Template
70
+ Currently running on {power_device}.
71
+ """)
72
+
73
+ with gr.Row():
74
+
75
+ prompt = gr.Text(
76
+ label="Prompt",
77
+ show_label=False,
78
+ max_lines=1,
79
+ placeholder="Enter your prompt",
80
+ container=False,
81
+ )
82
+
83
+ run_button = gr.Button("Run", scale=0)
84
+
85
+ result = gr.Image(label="Result", show_label=False)
86
+
87
+ # with gr.Accordion("Advanced Settings", open=False):
88
+
89
+ # negative_prompt = gr.Text(
90
+ # label="Negative prompt",
91
+ # max_lines=1,
92
+ # placeholder="Enter a negative prompt",
93
+ # visible=False,
94
+ # )
95
+
96
+ # seed = gr.Slider(
97
+ # label="Seed",
98
+ # minimum=0,
99
+ # maximum=MAX_SEED,
100
+ # step=1,
101
+ # value=0,
102
+ # )
103
+
104
+ # randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
105
+
106
+ # with gr.Row():
107
+
108
+ # width = gr.Slider(
109
+ # label="Width",
110
+ # minimum=256,
111
+ # maximum=MAX_IMAGE_SIZE,
112
+ # step=32,
113
+ # value=512,
114
+ # )
115
+
116
+ # height = gr.Slider(
117
+ # label="Height",
118
+ # minimum=256,
119
+ # maximum=MAX_IMAGE_SIZE,
120
+ # step=32,
121
+ # value=512,
122
+ # )
123
+
124
+ # with gr.Row():
125
+
126
+ # guidance_scale = gr.Slider(
127
+ # label="Guidance scale",
128
+ # minimum=0.0,
129
+ # maximum=10.0,
130
+ # step=0.1,
131
+ # value=0.0,
132
+ # )
133
+
134
+ # num_inference_steps = gr.Slider(
135
+ # label="Number of inference steps",
136
+ # minimum=1,
137
+ # maximum=12,
138
+ # step=1,
139
+ # value=2,
140
+ # )
141
+
142
+ gr.Examples(
143
+ examples = examples,
144
+ inputs = [prompt]
145
+ )
146
+
147
+ run_button.click(
148
+ fn = fake_diffusion,
149
+ inputs = [prompt],#, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
150
+ outputs = [result]
151
+ )
152
+
153
+ demo.queue().launch()
download.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import gradio as gr
3
+
4
+ def upload_file(filepath):
5
+ name = Path(filepath).name
6
+ return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
7
+
8
+ def download_file():
9
+ return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
10
+
11
+ with gr.Blocks() as demo:
12
+ gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
13
+ with gr.Row():
14
+ u = gr.UploadButton("Upload a file", file_count="single")
15
+ d = gr.DownloadButton("Download the file", visible=False)
16
+
17
+ u.upload(upload_file, u, [u, d])
18
+ d.click(download_file, None, [u, d])
19
+
20
+ if __name__ == "__main__":
21
+ demo.launch()
edit.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def predict(im):
4
+ return im["composite"]
5
+
6
+ with gr.Blocks() as demo:
7
+ with gr.Row():
8
+ im = gr.ImageEditor(
9
+ type="numpy",
10
+ #crop_size="1:1",
11
+ )
12
+ im_preview = gr.Image()
13
+
14
+ im.change(predict, outputs=im_preview, inputs=im, show_progress="hidden")
15
+
16
+ if __name__ == "__main__":
17
+ demo.launch()
gallery.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # @Time : 2023/10/12 13:48
3
+ # @Author : XyZeng
4
+
5
+ import os
6
+ import gradio as gr
7
+
8
+ def display_images():
9
+ img_dir='/home/kun/code/3d/poetry3d/image'
10
+ imgs_List=[ os.path.join(img_dir,name)
11
+ for name in sorted(os.listdir(img_dir))
12
+ if name.endswith(('.png','.jpg','.webp','.tif','.jpeg'))]
13
+ return imgs_List
14
+
15
+ with gr.Blocks() as demo:
16
+
17
+ gallery=gr.Gallery(show_label=False)
18
+ btn = gr.Button("刷新画廊", scale=0)
19
+ btn.click(display_images, None, gallery)
20
+
21
+ if __name__ == "__main__":
22
+
23
+ demo.launch()
24
+
image.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+
4
+
5
+ def upload(path):
6
+ headers = {'Authorization': 'YxKXccVDyLPhodqaDg4BIYNeJXSuCbkX'}
7
+ files = {'smfile': open(path, 'rb')}
8
+ url = 'https://sm.ms/api/v2/upload'
9
+ res = requests.post(url, files=files, headers=headers).json()
10
+ print(res['data']['url'])
11
+
12
+
13
+ if __name__ == "__main__":
14
+ upload('/home/kun/code/3d/poetry3d/mountain_1.png')
image/20240811_015338.png ADDED
image/20240811_102821.png ADDED
image/20240811_222255.png ADDED
image/20240821_211959.png ADDED
image/20240821_212023.png ADDED
image/20240821_213415.png ADDED
image/20240827_150253.png ADDED
image/20240827_150512.png ADDED
image/20240827_150844.png ADDED
image/20240827_150925.png ADDED
image/20240827_151634.png ADDED
image/20240827_151709.png ADDED
image/20240827_151726.png ADDED
image/20240827_151818.png ADDED
image/20240827_152822.png ADDED
image/20240827_153743.png ADDED
image/20240827_153755.png ADDED
image/20240827_153909.png ADDED
image/20240827_154109.png ADDED
image/20240827_154454.png ADDED
image/20240827_154612.png ADDED
image/20240827_154657.png ADDED
image/20240827_155031.png ADDED
image/20240827_155845.png ADDED
image/20240827_160025.png ADDED
image/20240827_160251.png ADDED
image/20240827_161618.png ADDED
image/20240827_162712.png ADDED
image/20240827_163016.png ADDED
image/20240827_163150.png ADDED
image/20240827_163623.png ADDED
image/20240827_164539.png ADDED
image/20240827_165109.png ADDED
image/20240827_165724.png ADDED
image/20240827_170339.png ADDED
image/20240827_170940.png ADDED
image/20240827_171439.png ADDED
image/20240827_171959.png ADDED
image/20240827_211152.png ADDED
image/20240827_214214.png ADDED