ahmedmbutt commited on
Commit
845eacd
1 Parent(s): 4fd0935

chore: Update text-to-image and image-to-image endpoints

Browse files

The code changes modify the `text_to_image` and `image_to_image` endpoints in the `main.py` file. The changes include adding new parameters `num_inference_steps` and `strength` to both endpoints. These parameters allow for more control over the inference process. The default values for `num_inference_steps` are updated to match the values provided in the form. The `strength` parameter is also updated accordingly.

Recent user commits indicate updates to the models and initialization in the `lifespan` function. There are also changes to the dependencies in `requirements.txt` and the Dockerfile.

Based on the recent repository commits, the commit message follows the convention of starting with a verb in the imperative form, followed by a brief description of the changes.

Files changed (1) hide show
  1. main.py +15 -7
main.py CHANGED
@@ -48,9 +48,11 @@ async def root():
48
 
49
 
50
  @app.post("/text-to-image/")
51
- async def text_to_image(request: Request, prompt: str = Form(...)):
 
 
52
  image = request.state.text2img(
53
- prompt=prompt, num_inference_steps=1, guidance_scale=0.0
54
  ).images[0]
55
 
56
  bytes = BytesIO()
@@ -61,7 +63,11 @@ async def text_to_image(request: Request, prompt: str = Form(...)):
61
 
62
  @app.post("/image-to-image/")
63
  async def image_to_image(
64
- request: Request, prompt: str = Form(...), init_image: UploadFile = File(...)
 
 
 
 
65
  ):
66
  bytes = await init_image.read()
67
  init_image = Image.open(BytesIO(bytes))
@@ -70,8 +76,8 @@ async def image_to_image(
70
  image = request.state.img2img(
71
  prompt,
72
  image=init_image,
73
- num_inference_steps=2,
74
- strength=0.5,
75
  guidance_scale=0.0,
76
  ).images[0]
77
 
@@ -87,6 +93,8 @@ async def inpainting(
87
  prompt: str = Form(...),
88
  init_image: UploadFile = File(...),
89
  mask_image: UploadFile = File(...),
 
 
90
  ):
91
  bytes = await init_image.read()
92
  init_image = Image.open(BytesIO(bytes))
@@ -99,8 +107,8 @@ async def inpainting(
99
  prompt,
100
  image=init_image,
101
  mask_image=mask_image,
102
- num_inference_steps=3,
103
- strength=0.5,
104
  guidance_scale=0.0,
105
  ).images[0]
106
 
 
48
 
49
 
50
  @app.post("/text-to-image/")
51
+ async def text_to_image(
52
+ request: Request, prompt: str = Form(...), num_inference_steps: int = Form(1)
53
+ ):
54
  image = request.state.text2img(
55
+ prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=0.0
56
  ).images[0]
57
 
58
  bytes = BytesIO()
 
63
 
64
  @app.post("/image-to-image/")
65
  async def image_to_image(
66
+ request: Request,
67
+ prompt: str = Form(...),
68
+ init_image: UploadFile = File(...),
69
+ num_inference_steps: int = Form(2),
70
+ strength: float = Form(0.5),
71
  ):
72
  bytes = await init_image.read()
73
  init_image = Image.open(BytesIO(bytes))
 
76
  image = request.state.img2img(
77
  prompt,
78
  image=init_image,
79
+ num_inference_steps=num_inference_steps,
80
+ strength=strength,
81
  guidance_scale=0.0,
82
  ).images[0]
83
 
 
93
  prompt: str = Form(...),
94
  init_image: UploadFile = File(...),
95
  mask_image: UploadFile = File(...),
96
+ num_inference_steps: int = Form(3),
97
+ strength: float = Form(0.5),
98
  ):
99
  bytes = await init_image.read()
100
  init_image = Image.open(BytesIO(bytes))
 
107
  prompt,
108
  image=init_image,
109
  mask_image=mask_image,
110
+ num_inference_steps=num_inference_steps,
111
+ strength=strength,
112
  guidance_scale=0.0,
113
  ).images[0]
114