Spaces:
Runtime error
Runtime error
Commit
Β·
0142bba
1
Parent(s):
e08f829
add: fastapi
Browse files- app.py +7 -0
- fastapi.py +17 -0
app.py
CHANGED
@@ -9,6 +9,8 @@ import spaces
|
|
9 |
import cv2
|
10 |
import base64
|
11 |
from io import BytesIO
|
|
|
|
|
12 |
from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline
|
13 |
|
14 |
model_id = "stabilityai/stable-diffusion-2-inpainting"
|
@@ -95,6 +97,10 @@ def clothing_try_on_base64(input_image_base64, mask_image_base64):
|
|
95 |
return image_to_base64(output_image)
|
96 |
|
97 |
|
|
|
|
|
|
|
|
|
98 |
def launch_interface_base64():
|
99 |
with gr.Blocks() as interface:
|
100 |
with gr.Row():
|
@@ -105,6 +111,7 @@ def launch_interface_base64():
|
|
105 |
submit = gr.Button("Apply")
|
106 |
|
107 |
submit.click(fn=clothing_try_on_base64, inputs=[inputImage, maskImage], outputs=[outputOne])
|
|
|
108 |
|
109 |
interface.launch(debug=True)
|
110 |
|
|
|
9 |
import cv2
|
10 |
import base64
|
11 |
from io import BytesIO
|
12 |
+
import uvicorn
|
13 |
+
from fastapi import app
|
14 |
from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline
|
15 |
|
16 |
model_id = "stabilityai/stable-diffusion-2-inpainting"
|
|
|
97 |
return image_to_base64(output_image)
|
98 |
|
99 |
|
100 |
+
def run_fastapi():
|
101 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
102 |
+
|
103 |
+
|
104 |
def launch_interface_base64():
|
105 |
with gr.Blocks() as interface:
|
106 |
with gr.Row():
|
|
|
111 |
submit = gr.Button("Apply")
|
112 |
|
113 |
submit.click(fn=clothing_try_on_base64, inputs=[inputImage, maskImage], outputs=[outputOne])
|
114 |
+
submit.click(fn=run_fastapi, inputs=[], outputs=[])
|
115 |
|
116 |
interface.launch(debug=True)
|
117 |
|
fastapi.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Created By: ishwor subedi
|
3 |
+
Date: 2024-10-04
|
4 |
+
"""
|
5 |
+
from CTO_TCP_V1.app import clothing_try_on_base64
|
6 |
+
from fastapi import FastAPI
|
7 |
+
|
8 |
+
app = FastAPI(title="CTO TCP V1")
|
9 |
+
|
10 |
+
|
11 |
+
@app.post("/clothingTryOn")
|
12 |
+
async def clothing_try_on(image: str, mask: str):
|
13 |
+
result = clothing_try_on_base64(image, mask)
|
14 |
+
|
15 |
+
return {"result": result}
|
16 |
+
|
17 |
+
|