Spaces:
Sleeping
Sleeping
fix for AttributeError: 'NoneType' object has no attribute 'is_db_ready'
Browse filesFile "/home/user/app/app.py", line 95, in chat_with_pdf
if not state.is_db_ready():
AttributeError: 'NoneType' object has no attribute 'is_db_ready'
app.py
CHANGED
|
@@ -45,7 +45,8 @@ def process_pdf(pdf_file, state):
|
|
| 45 |
if state.is_db_ready():
|
| 46 |
return (
|
| 47 |
gr.update(interactive=False),
|
| 48 |
-
gr.update(visible=True)
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
# Create a new session and directory for the user
|
|
@@ -74,10 +75,11 @@ def process_pdf(pdf_file, state):
|
|
| 74 |
|
| 75 |
gr.Info("PDF processed successfully! You can now ask questions about the document.")
|
| 76 |
|
| 77 |
-
# Return updates to the UI components
|
| 78 |
return (
|
| 79 |
gr.update(interactive=False),
|
| 80 |
-
gr.update(visible=True)
|
|
|
|
| 81 |
)
|
| 82 |
except Exception as e:
|
| 83 |
# Clean up the directory in case of an error
|
|
@@ -87,7 +89,8 @@ def process_pdf(pdf_file, state):
|
|
| 87 |
# Re-enable the file upload in case of error
|
| 88 |
return (
|
| 89 |
gr.update(interactive=True),
|
| 90 |
-
gr.update(visible=False)
|
|
|
|
| 91 |
)
|
| 92 |
|
| 93 |
# Function to handle user queries
|
|
@@ -159,7 +162,7 @@ with gr.Blocks(title="PDF Chatbot") as demo:
|
|
| 159 |
file_upload_input.upload(
|
| 160 |
fn=process_pdf,
|
| 161 |
inputs=[file_upload_input, state],
|
| 162 |
-
outputs=[file_upload_input, chat_interface]
|
| 163 |
)
|
| 164 |
|
| 165 |
demo.launch()
|
|
|
|
| 45 |
if state.is_db_ready():
|
| 46 |
return (
|
| 47 |
gr.update(interactive=False),
|
| 48 |
+
gr.update(visible=True),
|
| 49 |
+
state
|
| 50 |
)
|
| 51 |
|
| 52 |
# Create a new session and directory for the user
|
|
|
|
| 75 |
|
| 76 |
gr.Info("PDF processed successfully! You can now ask questions about the document.")
|
| 77 |
|
| 78 |
+
# Return updates to the UI components and the new state
|
| 79 |
return (
|
| 80 |
gr.update(interactive=False),
|
| 81 |
+
gr.update(visible=True),
|
| 82 |
+
state
|
| 83 |
)
|
| 84 |
except Exception as e:
|
| 85 |
# Clean up the directory in case of an error
|
|
|
|
| 89 |
# Re-enable the file upload in case of error
|
| 90 |
return (
|
| 91 |
gr.update(interactive=True),
|
| 92 |
+
gr.update(visible=False),
|
| 93 |
+
state
|
| 94 |
)
|
| 95 |
|
| 96 |
# Function to handle user queries
|
|
|
|
| 162 |
file_upload_input.upload(
|
| 163 |
fn=process_pdf,
|
| 164 |
inputs=[file_upload_input, state],
|
| 165 |
+
outputs=[file_upload_input, chat_interface, state]
|
| 166 |
)
|
| 167 |
|
| 168 |
demo.launch()
|