Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
removed column deprecation param
Browse files- pages/Semantic_Search.py +84 -84
pages/Semantic_Search.py
CHANGED
|
@@ -287,97 +287,97 @@ if(search_all_type==True):
|
|
| 287 |
|
| 288 |
|
| 289 |
def generate_images(tab,inp_):
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
)
|
| 306 |
-
|
| 307 |
-
if(inp_!=st.session_state.image_prompt):
|
| 308 |
-
print("call bedrocck")
|
| 309 |
-
response = bedrock_.invoke_model(
|
| 310 |
-
modelId="amazon.titan-image-generator-v1", body=request
|
| 311 |
)
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
os.mkdir(gen_images_dir)
|
| 319 |
-
width_ = 200
|
| 320 |
-
height_ = 200
|
| 321 |
-
index_ = 0
|
| 322 |
-
#if(inp_!=st.session_state.image_prompt):
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
with tab:
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
# if(st.session_state.input_rad_1 is None):
|
| 338 |
-
# rand_ = ""
|
| 339 |
-
# else:
|
| 340 |
-
# rand_ = st.session_state.input_rad_1
|
| 341 |
-
# if(inp_!=st.session_state.image_prompt+rand_):
|
| 342 |
-
# with rad1:
|
| 343 |
-
# sel_rad_1 = st.radio("Choose one image", ["1","2","3"],index=None, horizontal = True,key = 'input_rad_1')
|
| 344 |
-
|
| 345 |
-
with tab:
|
| 346 |
-
#sel_image = st.radio("", ["1","2","3"],index=None, horizontal = True)
|
| 347 |
-
if(st.session_state.img_container!=""):
|
| 348 |
-
st.session_state.img_container.empty()
|
| 349 |
-
place_ = st.empty()
|
| 350 |
-
img1, img2,img3 = place_.columns([30,30,30])
|
| 351 |
-
st.session_state.img_container = place_
|
| 352 |
-
img_arr = [img1, img2,img3]
|
| 353 |
-
|
| 354 |
-
base64_image_data = image_
|
| 355 |
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
-
print("perform multimodal search")
|
| 359 |
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
image.save(parent_dirname+"/gen_images/"+filename+"-resized_display."+file_type)
|
| 374 |
-
|
| 375 |
-
with img_arr[index_]:
|
| 376 |
-
placeholder_ = st.empty()
|
| 377 |
-
placeholder_.image(parent_dirname+"/gen_images/"+filename+"-resized_display."+file_type)
|
| 378 |
-
|
| 379 |
-
index_ = index_ + 1
|
| 380 |
-
|
| 381 |
|
| 382 |
|
| 383 |
def handle_input():
|
|
|
|
| 287 |
|
| 288 |
|
| 289 |
def generate_images(tab,inp_):
|
| 290 |
+
#write_top_bar()
|
| 291 |
+
seed = random.randint(1, 10)
|
| 292 |
+
request = json.dumps(
|
| 293 |
+
{
|
| 294 |
+
"taskType": "TEXT_IMAGE",
|
| 295 |
+
"textToImageParams": {"text": st.session_state.image_prompt},
|
| 296 |
+
"imageGenerationConfig": {
|
| 297 |
+
"numberOfImages": 3,
|
| 298 |
+
"quality": "standard",
|
| 299 |
+
"cfgScale": 8.0,
|
| 300 |
+
"height": 512,
|
| 301 |
+
"width": 512,
|
| 302 |
+
"seed": seed,
|
| 303 |
+
},
|
| 304 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
)
|
| 306 |
+
|
| 307 |
+
if(inp_!=st.session_state.image_prompt):
|
| 308 |
+
print("call bedrocck")
|
| 309 |
+
response = bedrock_.invoke_model(
|
| 310 |
+
modelId="amazon.titan-image-generator-v1", body=request
|
| 311 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
+
response_body = json.loads(response["body"].read())
|
| 314 |
+
st.session_state.img_gen = response_body["images"]
|
| 315 |
+
gen_images_dir = os.path.join(parent_dirname, "gen_images")
|
| 316 |
+
if os.path.exists(gen_images_dir):
|
| 317 |
+
shutil.rmtree(gen_images_dir)
|
| 318 |
+
os.mkdir(gen_images_dir)
|
| 319 |
+
width_ = 200
|
| 320 |
+
height_ = 200
|
| 321 |
+
index_ = 0
|
| 322 |
+
#if(inp_!=st.session_state.image_prompt):
|
| 323 |
+
|
| 324 |
+
if(len(st.session_state.img_gen)==0 and st.session_state.clear_ == True):
|
| 325 |
+
#write_top_bar()
|
| 326 |
+
placeholder1 = st.empty()
|
| 327 |
+
with tab:
|
| 328 |
+
with placeholder1.container():
|
| 329 |
+
st.empty()
|
| 330 |
+
|
| 331 |
+
images_dis = []
|
| 332 |
+
for image_ in st.session_state.img_gen:
|
| 333 |
+
st.session_state.radio_disabled = False
|
| 334 |
+
if(index_==0):
|
| 335 |
+
# with tab:
|
| 336 |
+
# rad1, rad2,rad3 = st.columns([98,1,1])
|
| 337 |
+
# if(st.session_state.input_rad_1 is None):
|
| 338 |
+
# rand_ = ""
|
| 339 |
+
# else:
|
| 340 |
+
# rand_ = st.session_state.input_rad_1
|
| 341 |
+
# if(inp_!=st.session_state.image_prompt+rand_):
|
| 342 |
+
# with rad1:
|
| 343 |
+
# sel_rad_1 = st.radio("Choose one image", ["1","2","3"],index=None, horizontal = True,key = 'input_rad_1')
|
| 344 |
+
|
| 345 |
with tab:
|
| 346 |
+
#sel_image = st.radio("", ["1","2","3"],index=None, horizontal = True)
|
| 347 |
+
if(st.session_state.img_container!=""):
|
| 348 |
+
st.session_state.img_container.empty()
|
| 349 |
+
place_ = st.empty()
|
| 350 |
+
img1, img2,img3 = place_.columns([30,30,30])
|
| 351 |
+
st.session_state.img_container = place_
|
| 352 |
+
img_arr = [img1, img2,img3]
|
| 353 |
+
|
| 354 |
+
base64_image_data = image_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
+
#st.session_state.gen_image_str = base64_image_data
|
| 357 |
+
|
| 358 |
+
print("perform multimodal search")
|
| 359 |
+
|
| 360 |
+
Image.MAX_IMAGE_PIXELS = 100000000
|
| 361 |
+
filename = st.session_state.image_prompt+"_gen_"+str(index_)
|
| 362 |
+
photo = parent_dirname+"/gen_images/"+filename+'.jpg'
|
| 363 |
+
imgdata = base64.b64decode(base64_image_data)
|
| 364 |
+
with open(photo, 'wb') as f:
|
| 365 |
+
f.write(imgdata)
|
| 366 |
|
|
|
|
| 367 |
|
| 368 |
+
|
| 369 |
+
with Image.open(photo) as image:
|
| 370 |
+
file_type = 'jpg'
|
| 371 |
+
path = image.filename.rsplit(".", 1)[0]
|
| 372 |
+
image.thumbnail((width_, height_))
|
| 373 |
+
image.save(parent_dirname+"/gen_images/"+filename+"-resized_display."+file_type)
|
| 374 |
|
| 375 |
+
with img_arr[index_]:
|
| 376 |
+
placeholder_ = st.empty()
|
| 377 |
+
placeholder_.image(parent_dirname+"/gen_images/"+filename+"-resized_display."+file_type)
|
| 378 |
+
|
| 379 |
+
index_ = index_ + 1
|
| 380 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
|
| 383 |
def handle_input():
|