nikhmr1235 commited on
Commit
9dcff61
·
verified ·
1 Parent(s): 187f700

attempt to fix AttributeError: 'function' object has no attribute 'is_db_ready' + PDF validation to limit file size <75MB only

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -49,6 +49,16 @@ def process_pdf(pdf_file, state):
49
  state
50
  )
51
 
 
 
 
 
 
 
 
 
 
 
52
  # Create a new session and directory for the user
53
  state = new_session()
54
  if not os.path.exists(state.vector_store_path):
@@ -130,7 +140,8 @@ def chat_with_pdf(message, history, state):
130
 
131
  # Gradio Interface
132
  with gr.Blocks(title="PDF Chatbot") as demo:
133
- state = gr.State(new_session)
 
134
 
135
  gr.Markdown(
136
  """
 
49
  state
50
  )
51
 
52
+ # File size validation
53
+ file_size_mb = os.path.getsize(pdf_file.name) / (1024 * 1024)
54
+ if file_size_mb >= 75:
55
+ gr.Error("File size exceeds the 75 MB limit. Please upload a smaller PDF.")
56
+ return (
57
+ gr.update(interactive=True),
58
+ gr.update(visible=False),
59
+ state
60
+ )
61
+
62
  # Create a new session and directory for the user
63
  state = new_session()
64
  if not os.path.exists(state.vector_store_path):
 
140
 
141
  # Gradio Interface
142
  with gr.Blocks(title="PDF Chatbot") as demo:
143
+ # Corrected: Initialize gr.State with the object returned by the function
144
+ state = gr.State(new_session())
145
 
146
  gr.Markdown(
147
  """