Update main.py
Browse files
main.py
CHANGED
@@ -138,8 +138,7 @@ Now, extract the core product name from the following:
|
|
138 |
|
139 |
{product_name}"""
|
140 |
|
141 |
-
|
142 |
-
async def chat(product_name: str = Form(...)):
|
143 |
try:
|
144 |
logger.info(f"Processing product name: {product_name}")
|
145 |
completion = client.chat.completions.create(
|
@@ -207,6 +206,9 @@ async def segment_image(
|
|
207 |
@app.post("/segment/langsam")
|
208 |
async def segment_image(image_url: str = Form(...), text_prompt: str = Form(...)):
|
209 |
try:
|
|
|
|
|
|
|
210 |
logger.info(f"Starting LangSAM segmentation for image URL: {image_url} with prompt: {text_prompt}")
|
211 |
image_pil = load_image_from_url(image_url)
|
212 |
image_array = np.array(image_pil)
|
@@ -234,7 +236,8 @@ async def segment_image(image_url: str = Form(...), text_prompt: str = Form(...)
|
|
234 |
"mask_only": mask_only_b64,
|
235 |
"boxes": results[0]["boxes"].tolist(),
|
236 |
"scores": results[0]["scores"].tolist(),
|
237 |
-
"labels": results[0]["labels"]
|
|
|
238 |
}
|
239 |
|
240 |
logger.info("LangSAM segmentation completed successfully")
|
|
|
138 |
|
139 |
{product_name}"""
|
140 |
|
141 |
+
def chat(product_name: str = Form(...)):
|
|
|
142 |
try:
|
143 |
logger.info(f"Processing product name: {product_name}")
|
144 |
completion = client.chat.completions.create(
|
|
|
206 |
@app.post("/segment/langsam")
|
207 |
async def segment_image(image_url: str = Form(...), text_prompt: str = Form(...)):
|
208 |
try:
|
209 |
+
# process text prompt using openai chat
|
210 |
+
text_prompt = chat(text_prompt)
|
211 |
+
|
212 |
logger.info(f"Starting LangSAM segmentation for image URL: {image_url} with prompt: {text_prompt}")
|
213 |
image_pil = load_image_from_url(image_url)
|
214 |
image_array = np.array(image_pil)
|
|
|
236 |
"mask_only": mask_only_b64,
|
237 |
"boxes": results[0]["boxes"].tolist(),
|
238 |
"scores": results[0]["scores"].tolist(),
|
239 |
+
"labels": results[0]["labels"],
|
240 |
+
"product_tag": text_prompt
|
241 |
}
|
242 |
|
243 |
logger.info("LangSAM segmentation completed successfully")
|