lfoppiano commited on
Commit
f52f043
1 Parent(s): 8b52607

update streamlit-pdf-viewer, fix chat wobbling

Browse files
Files changed (2) hide show
  1. requirements.txt +2 -2
  2. streamlit_app.py +35 -21
requirements.txt CHANGED
@@ -7,7 +7,7 @@ grobid_tei_xml==0.1.3
7
  tqdm==4.66.2
8
  pyyaml==6.0.1
9
  pytest==8.1.1
10
- streamlit==1.36.0
11
  lxml
12
  Beautifulsoup4
13
  python-dotenv
@@ -24,6 +24,6 @@ typing-inspect==0.9.0
24
  typing_extensions==4.11.0
25
  pydantic==2.6.4
26
  sentence_transformers==2.6.1
27
- streamlit-pdf-viewer==0.0.14
28
  umap-learn
29
  plotly
 
7
  tqdm==4.66.2
8
  pyyaml==6.0.1
9
  pytest==8.1.1
10
+ streamlit==1.37.0
11
  lxml
12
  Beautifulsoup4
13
  python-dotenv
 
24
  typing_extensions==4.11.0
25
  pydantic==2.6.4
26
  sentence_transformers==2.6.1
27
+ streamlit-pdf-viewer==0.0.17
28
  umap-learn
29
  plotly
streamlit_app.py CHANGED
@@ -31,8 +31,8 @@ OPENAI_EMBEDDINGS = [
31
  ]
32
 
33
  OPEN_MODELS = {
34
- 'mistral-7b-instruct-v0.3': 'mistralai/Mistral-7B-Instruct-v0.2',
35
- # 'Phi-3-mini-128k-instruct': "microsoft/Phi-3-mini-128k-instruct",
36
  'Phi-3-mini-4k-instruct': "microsoft/Phi-3-mini-4k-instruct"
37
  }
38
 
@@ -109,6 +109,20 @@ st.set_page_config(
109
  }
110
  )
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
  def new_file():
114
  st.session_state['loaded_embeddings'] = None
@@ -154,8 +168,8 @@ def init_qa(model, embeddings_name=None, api_key=None):
154
  chat = HuggingFaceEndpoint(
155
  repo_id=OPEN_MODELS[model],
156
  temperature=0.01,
157
- max_new_tokens=2048,
158
- model_kwargs={"max_length": 4096}
159
  )
160
  embeddings = HuggingFaceEmbeddings(
161
  model_name=OPEN_EMBEDDINGS[embeddings_name])
@@ -401,21 +415,21 @@ def generate_color_gradient(num_elements):
401
 
402
  with right_column:
403
  if st.session_state.loaded_embeddings and question and len(question) > 0 and st.session_state.doc_id:
 
 
 
404
  for message in st.session_state.messages:
405
- with messages.chat_message(message["role"]):
406
- if message['mode'] == "llm":
407
- messages.chat_message(message["role"]).markdown(message["content"], unsafe_allow_html=True)
408
- elif message['mode'] == "embeddings":
409
- messages.chat_message(message["role"]).write(message["content"])
410
- if message['mode'] == "question_coefficient":
411
- messages.chat_message(message["role"]).markdown(message["content"], unsafe_allow_html=True)
412
  if model not in st.session_state['rqa']:
413
  st.error("The API Key for the " + model + " is missing. Please add it before sending any query. `")
414
  st.stop()
415
 
416
- messages.chat_message("user").markdown(question)
417
- st.session_state.messages.append({"role": "user", "mode": mode, "content": question})
418
-
419
  text_response = None
420
  if mode == "embeddings":
421
  with placeholder:
@@ -472,10 +486,10 @@ with right_column:
472
 
473
  with left_column:
474
  if st.session_state['binary']:
475
- pdf_viewer(
476
- input=st.session_state['binary'],
477
- annotation_outline_size=2,
478
- annotations=st.session_state['annotations'],
479
- render_text=True,
480
- height=600
481
- )
 
31
  ]
32
 
33
  OPEN_MODELS = {
34
+ 'Mistral-Nemo-Instruct-2407': 'mistralai/Mistral-Nemo-Instruct-2407',
35
+ 'mistral-7b-instruct-v0.3': 'mistralai/Mistral-7B-Instruct-v0.3',
36
  'Phi-3-mini-4k-instruct': "microsoft/Phi-3-mini-4k-instruct"
37
  }
38
 
 
109
  }
110
  )
111
 
112
+ st.markdown(
113
+ """
114
+ <style>
115
+ .block-container {
116
+ padding-top: 3rem;
117
+ padding-bottom: 1rem;
118
+ padding-left: 1rem;
119
+ padding-right: 1rem;
120
+ }
121
+ </style>
122
+ """,
123
+ unsafe_allow_html=True
124
+ )
125
+
126
 
127
  def new_file():
128
  st.session_state['loaded_embeddings'] = None
 
168
  chat = HuggingFaceEndpoint(
169
  repo_id=OPEN_MODELS[model],
170
  temperature=0.01,
171
+ max_new_tokens=4092,
172
+ model_kwargs={"max_length": 8192}
173
  )
174
  embeddings = HuggingFaceEmbeddings(
175
  model_name=OPEN_EMBEDDINGS[embeddings_name])
 
415
 
416
  with right_column:
417
  if st.session_state.loaded_embeddings and question and len(question) > 0 and st.session_state.doc_id:
418
+ # messages.chat_message("user").markdown(question)
419
+ st.session_state.messages.append({"role": "user", "mode": mode, "content": question})
420
+
421
  for message in st.session_state.messages:
422
+ # with messages.chat_message(message["role"]):
423
+ if message['mode'] == "llm":
424
+ messages.chat_message(message["role"]).markdown(message["content"], unsafe_allow_html=True)
425
+ elif message['mode'] == "embeddings":
426
+ messages.chat_message(message["role"]).write(message["content"])
427
+ elif message['mode'] == "question_coefficient":
428
+ messages.chat_message(message["role"]).markdown(message["content"], unsafe_allow_html=True)
429
  if model not in st.session_state['rqa']:
430
  st.error("The API Key for the " + model + " is missing. Please add it before sending any query. `")
431
  st.stop()
432
 
 
 
 
433
  text_response = None
434
  if mode == "embeddings":
435
  with placeholder:
 
486
 
487
  with left_column:
488
  if st.session_state['binary']:
489
+ with st.container(height=600):
490
+ pdf_viewer(
491
+ input=st.session_state['binary'],
492
+ annotation_outline_size=2,
493
+ annotations=st.session_state['annotations'],
494
+ render_text=True
495
+ )