Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
colpali fix
Browse files
pages/Multimodal_Conversational_Search.py
CHANGED
|
@@ -277,67 +277,22 @@ def render_answer(question,answer,index,res_img):
|
|
| 277 |
with col2:
|
| 278 |
ans_ = answer['answer']
|
| 279 |
st.write(ans_)
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
# def stream_():
|
| 284 |
-
# #use for streaming response on the client side
|
| 285 |
-
# for word in ans_.split(" "):
|
| 286 |
-
# yield word + " "
|
| 287 |
-
# time.sleep(0.04)
|
| 288 |
-
# #use for streaming response from Llm directly
|
| 289 |
-
# if(isinstance(ans_,botocore.eventstream.EventStream)):
|
| 290 |
-
# for event in ans_:
|
| 291 |
-
# chunk = event.get('chunk')
|
| 292 |
-
|
| 293 |
-
# if chunk:
|
| 294 |
-
|
| 295 |
-
# chunk_obj = json.loads(chunk.get('bytes').decode())
|
| 296 |
-
|
| 297 |
-
# if('content_block' in chunk_obj or ('delta' in chunk_obj and 'text' in chunk_obj['delta'])):
|
| 298 |
-
# key_ = list(chunk_obj.keys())[2]
|
| 299 |
-
# text = chunk_obj[key_]['text']
|
| 300 |
-
|
| 301 |
-
# clear_output(wait=True)
|
| 302 |
-
# output.append(text)
|
| 303 |
-
# yield text
|
| 304 |
-
# time.sleep(0.04)
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
# if(index == len(st.session_state.questions_)):
|
| 309 |
-
# st.write_stream(stream_)
|
| 310 |
-
# if(isinstance(st.session_state.answers_[index-1]['answer'],botocore.eventstream.EventStream)):
|
| 311 |
-
# st.session_state.answers_[index-1]['answer'] = "".join(output)
|
| 312 |
-
# else:
|
| 313 |
-
# st.write(ans_)
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
# polly_response = polly_client.synthesize_speech(VoiceId='Joanna',
|
| 317 |
-
# OutputFormat='ogg_vorbis',
|
| 318 |
-
# Text = ans_,
|
| 319 |
-
# Engine = 'neural')
|
| 320 |
-
|
| 321 |
-
# audio_col1, audio_col2 = st.columns([50,50])
|
| 322 |
-
# with audio_col1:
|
| 323 |
-
# st.audio(polly_response['AudioStream'].read(), format="audio/ogg")
|
| 324 |
-
|
| 325 |
rdn_key_1 = ''.join([random.choice(string.ascii_letters)
|
| 326 |
for _ in range(10)])
|
| 327 |
def show_maxsim():
|
| 328 |
st.session_state.show_columns = True
|
| 329 |
st.session_state.maxSimImages = colpali.img_highlight(st.session_state.top_img, st.session_state.query_token_vectors, st.session_state.query_tokens)
|
|
|
|
|
|
|
|
|
|
| 330 |
handle_input()
|
| 331 |
with placeholder.container():
|
| 332 |
-
render_all()
|
|
|
|
| 333 |
if(st.session_state.input_is_colpali):
|
| 334 |
st.button("Show similarity map",key=rdn_key_1,on_click = show_maxsim)
|
| 335 |
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
#st.markdown("<div style='font-size:18px;padding:3px 7px 3px 7px;borderWidth: 0px;borderColor: red;borderStyle: solid;border-radius: 10px;'>"+ans_+"</div>", unsafe_allow_html = True)
|
| 339 |
-
#st.markdown("<div style='color:#e28743';padding:3px 7px 3px 7px;borderWidth: 0px;borderColor: red;borderStyle: solid;width: fit-content;height: fit-content;border-radius: 10px;'><b>Relevant images from the document :</b></div>", unsafe_allow_html = True)
|
| 340 |
-
#st.write("")
|
| 341 |
colu1,colu2,colu3 = st.columns([4,82,20])
|
| 342 |
with colu2:
|
| 343 |
with st.expander("Relevant Sources:"):
|
|
@@ -396,11 +351,6 @@ def render_answer(question,answer,index,res_img):
|
|
| 396 |
|
| 397 |
|
| 398 |
with col_3:
|
| 399 |
-
|
| 400 |
-
#st.markdown("<div style='color:#e28743;borderWidth: 0px;borderColor: red;borderStyle: solid;width: fit-content;height: fit-content;border-radius: 5px;'><b>"+",".join(st.session_state.input_rag_searchType)+"</b></div>", unsafe_allow_html = True)
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
if(index == len(st.session_state.questions_)):
|
| 405 |
|
| 406 |
rdn_key = ''.join([random.choice(string.ascii_letters)
|
|
|
|
| 277 |
with col2:
|
| 278 |
ans_ = answer['answer']
|
| 279 |
st.write(ans_)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
rdn_key_1 = ''.join([random.choice(string.ascii_letters)
|
| 281 |
for _ in range(10)])
|
| 282 |
def show_maxsim():
|
| 283 |
st.session_state.show_columns = True
|
| 284 |
st.session_state.maxSimImages = colpali.img_highlight(st.session_state.top_img, st.session_state.query_token_vectors, st.session_state.query_tokens)
|
| 285 |
+
st.session_state.input_query = st.session_state.questions_[-1]["question"]
|
| 286 |
+
st.session_state.answers_.pop()
|
| 287 |
+
st.session_state.questions_.pop()
|
| 288 |
handle_input()
|
| 289 |
with placeholder.container():
|
| 290 |
+
render_all()
|
| 291 |
+
|
| 292 |
if(st.session_state.input_is_colpali):
|
| 293 |
st.button("Show similarity map",key=rdn_key_1,on_click = show_maxsim)
|
| 294 |
|
| 295 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
colu1,colu2,colu3 = st.columns([4,82,20])
|
| 297 |
with colu2:
|
| 298 |
with st.expander("Relevant Sources:"):
|
|
|
|
| 351 |
|
| 352 |
|
| 353 |
with col_3:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
if(index == len(st.session_state.questions_)):
|
| 355 |
|
| 356 |
rdn_key = ''.join([random.choice(string.ascii_letters)
|