rogerxavier commited on
Commit
28a8a5f
1 Parent(s): 89ea09f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -40
app.py CHANGED
@@ -1,43 +1,57 @@
1
  from typing import List
2
  from pydantic import BaseModel
3
- from lama_cleaner.server import main
 
 
4
 
5
- class FakeArgs(BaseModel):
6
- host: str = "0.0.0.0"
7
- port: int = 7860
8
- model: str = 'lama'
9
- hf_access_token: str = ""
10
- sd_enable_xformers: bool = False
11
- sd_disable_nsfw: bool = False
12
- sd_cpu_textencoder: bool = True
13
- sd_controlnet: bool = False
14
- sd_controlnet_method: str = "control_v11p_sd15_canny"
15
- sd_local_model_path: str = ""
16
- sd_run_local: bool = False
17
- local_files_only: bool = False
18
- cpu_offload: bool = False
19
- device: str = "cpu"
20
- gui: bool = False
21
- gui_size: List[int] = [1000, 1000]
22
- input: str = ''
23
- disable_model_switch: bool = True
24
- debug: bool = False
25
- no_half: bool = False
26
- disable_nsfw: bool = False
27
- enable_xformers: bool = False
28
- enable_interactive_seg: bool = True
29
- interactive_seg_model: str = "vit_b"
30
- interactive_seg_device: str = "cpu"
31
- enable_remove_bg: bool = False
32
- enable_anime_seg: bool = False
33
- enable_realesrgan: bool = False
34
- enable_gfpgan: bool = False
35
- gfpgan_device: str = "cpu"
36
- enable_restoreformer: bool = False
37
- enable_gif: bool = False
38
- quality: int = 95
39
- model_dir: str = None
40
- output_dir: str = None
41
-
42
- if __name__ == "__main__":
43
- main(FakeArgs())
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from typing import List
2
  from pydantic import BaseModel
3
+ from lama_cleaner.server import process
4
+ import uvicorn
5
+ from fastapi import FastAPI
6
 
7
+ @app.on_event("startup")
8
+ async def app_start():
9
+ image_bytes = open('image.jpg', 'rb')
10
+ mask_bytes = open('mask.jpg', 'rb')
11
+ # 将字节数据转换为Base64编码的字符串
12
+
13
+ files = {
14
+ "image": image_bytes,
15
+ "mask":mask_bytes
16
+ }
17
+ payload = {
18
+ "ldmSteps": 25,
19
+ "ldmSampler": "plms",
20
+ "zitsWireframe": True,
21
+ "hdStrategy": "Crop",
22
+ "hdStrategyCropMargin": 196,
23
+ "hdStrategyCropTrigerSize": 800,
24
+ "hdStrategyResizeLimit": 2048,
25
+ "prompt": "",
26
+ "negativePrompt": "",
27
+ "croperX": 307,
28
+ "croperY": 544,
29
+ "croperHeight": 512,
30
+ "croperWidth": 512,
31
+ "useCroper": False,
32
+ "sdMaskBlur": 5,
33
+ "sdStrength": 0.75,
34
+ "sdSteps": 50,
35
+ "sdGuidanceScale": 7.5,
36
+ "sdSampler": "uni_pc",
37
+ "sdSeed": -1,
38
+ "sdMatchHistograms": False,
39
+ "sdScale": 1,
40
+ "cv2Radius": 5,
41
+ "cv2Flag": "INPAINT_NS",
42
+ "paintByExampleSteps": 50,
43
+ "paintByExampleGuidanceScale": 7.5,
44
+ "paintByExampleSeed": -1,
45
+ "paintByExampleMaskBlur": 5,
46
+ "paintByExampleMatchHistograms": False,
47
+ "p2pSteps": 50,
48
+ "p2pImageGuidanceScale": 1.5,
49
+ "p2pGuidanceScale": 7.5,
50
+ "controlnet_conditioning_scale": 0.4,
51
+ "controlnet_method": "control_v11p_sd15_canny"
52
+ }#payload用data
53
+
54
+ resp = process(files=files,payload=payload)
55
+ print(resp)
56
+ if __name__ == '__main__':
57
+ uvicorn.run(app, host='0.0.0.0', port=7860)