-
Notifications
You must be signed in to change notification settings - Fork 6
Error handling for Grobid when not responding #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sanakhamassi
wants to merge
6
commits into
ScienciaLAB:main
Choose a base branch
from
Sanakhamassi:fix/Display-an-error-message-when-grobid-is-not-responding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6a83c20
Add error handling for Grobid service when not responding
Sanakhamassi 5670b4b
Update GrobidProcessor initialization and enhance error handling in S…
Sanakhamassi cf29781
Fix missing space in error message
Sanakhamassi a7f3546
use temporary file with suffix and ensure cleanup
Sanakhamassi 76673e2
Enhance DocumentQAEngine with ping_grobid_server parameter and update…
Sanakhamassi 24c0f84
add tests for GrobidServiceError handling
Sanakhamassi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,20 +4,19 @@ | |
| from tempfile import NamedTemporaryFile | ||
|
|
||
| import dotenv | ||
| import streamlit as st | ||
| from grobid_quantities.quantities import QuantitiesAPI | ||
| from langchain.memory import ConversationBufferMemory | ||
| from langchain_openai import ChatOpenAI | ||
| from streamlit_pdf_viewer import pdf_viewer | ||
|
|
||
| from document_qa.custom_embeddings import ModalEmbeddings | ||
| from document_qa.document_qa_engine import DocumentQAEngine, DataStorage | ||
| from document_qa.grobid_processors import GrobidAggregationProcessor, decorate_text_with_annotations, GrobidServiceError | ||
| from document_qa.ner_client_generic import NERClientGeneric | ||
|
|
||
| dotenv.load_dotenv(override=True) | ||
|
|
||
| import streamlit as st | ||
| from document_qa.document_qa_engine import DocumentQAEngine, DataStorage | ||
| from document_qa.grobid_processors import GrobidAggregationProcessor, decorate_text_with_annotations | ||
|
|
||
| API_MODELS = { | ||
| "microsoft/Phi-4-mini-instruct": os.environ["PHI_URL"], | ||
| "Qwen/Qwen3-0.6B": os.environ["QWEN_URL"] | ||
|
|
@@ -314,19 +313,28 @@ def play_old_messages(container): | |
| st.stop() | ||
|
|
||
| with left_column: | ||
| with st.spinner('Reading file, calling Grobid, and creating in-memory embeddings...'): | ||
| binary = uploaded_file.getvalue() | ||
| tmp_file = NamedTemporaryFile() | ||
| tmp_file.write(bytearray(binary)) | ||
| st.session_state['binary'] = binary | ||
|
|
||
| st.session_state['doc_id'] = hash = st.session_state['rqa'][model].create_memory_embeddings( | ||
| tmp_file.name, | ||
| chunk_size=chunk_size, | ||
| perc_overlap=0.1 | ||
| ) | ||
| st.session_state['loaded_embeddings'] = True | ||
| st.session_state.messages = [] | ||
| try: | ||
| with st.spinner('Reading file, calling Grobid, and creating in-memory embeddings...'): | ||
| binary = uploaded_file.getvalue() | ||
| tmp_file = NamedTemporaryFile() | ||
| tmp_file.write(bytearray(binary)) | ||
| st.session_state['binary'] = binary | ||
|
|
||
| st.session_state['doc_id'] = hash = st.session_state['rqa'][model].create_memory_embeddings( | ||
| tmp_file.name, | ||
| chunk_size=chunk_size, | ||
| perc_overlap=0.1 | ||
| ) | ||
|
lfoppiano marked this conversation as resolved.
Outdated
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, @Sanakhamassi here you need to either add tempFile in the with () or handle that somehow |
||
| st.session_state['loaded_embeddings'] = True | ||
| st.session_state.messages = [] | ||
| except GrobidServiceError as exc: | ||
| message = str(exc).strip() or "Grobid is not responding" | ||
| status = f" (status {exc.status_code})" if exc.status_code else "" | ||
| st.session_state['doc_id'] = None | ||
| st.session_state['loaded_embeddings'] = False | ||
| st.session_state['uploaded'] = False | ||
| st.error(f"{message} Please try later.") | ||
|
|
||
| st.stop() | ||
|
|
||
|
|
||
| def rgb_to_hex(rgb): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sanakhamassi why was this removed?