Spaces:
Sleeping
Sleeping
attempt 3 to fix UI visbility issue
Browse files
app.py
CHANGED
|
@@ -24,12 +24,12 @@ class PDFChatbot:
|
|
| 24 |
def process_pdf(self, pdf_file):
|
| 25 |
try:
|
| 26 |
if self.state.is_db_ready():
|
| 27 |
-
return
|
| 28 |
|
| 29 |
file_size_mb = os.path.getsize(pdf_file.name) / (1024 * 1024)
|
| 30 |
if file_size_mb >= 75:
|
| 31 |
gr.Error("File size exceeds the 75 MB limit. Please upload a smaller PDF.")
|
| 32 |
-
return
|
| 33 |
|
| 34 |
self.state = SessionState()
|
| 35 |
doc = fitz.open(pdf_file.name)
|
|
@@ -49,12 +49,10 @@ class PDFChatbot:
|
|
| 49 |
)
|
| 50 |
|
| 51 |
gr.Info("PDF processed successfully! You can now ask questions about the document.")
|
| 52 |
-
return gr.update(interactive=False)
|
| 53 |
except Exception as e:
|
| 54 |
if os.path.exists(self.state.vector_store_path):
|
| 55 |
shutil.rmtree(self.state.vector_store_path)
|
| 56 |
gr.Error(f"An error occurred: {str(e)}")
|
| 57 |
-
return gr.update(interactive=True)
|
| 58 |
|
| 59 |
def chat_with_pdf(self, message, history):
|
| 60 |
if not self.state.is_db_ready():
|
|
@@ -126,20 +124,14 @@ with gr.Blocks(title="PDF Chatbot") as demo:
|
|
| 126 |
visible=False
|
| 127 |
)
|
| 128 |
|
| 129 |
-
def
|
| 130 |
-
|
|
|
|
| 131 |
|
| 132 |
file_upload_input.upload(
|
| 133 |
-
fn=
|
| 134 |
inputs=[file_upload_input],
|
| 135 |
-
outputs=[file_upload_input]
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
file_upload_input.upload(
|
| 139 |
-
fn=show_chat_interface,
|
| 140 |
-
inputs=[gr.Number(value=1, visible=False)],
|
| 141 |
-
outputs=[chat_interface],
|
| 142 |
-
preprocess=False
|
| 143 |
)
|
| 144 |
|
| 145 |
demo.launch()
|
|
|
|
| 24 |
def process_pdf(self, pdf_file):
|
| 25 |
try:
|
| 26 |
if self.state.is_db_ready():
|
| 27 |
+
return
|
| 28 |
|
| 29 |
file_size_mb = os.path.getsize(pdf_file.name) / (1024 * 1024)
|
| 30 |
if file_size_mb >= 75:
|
| 31 |
gr.Error("File size exceeds the 75 MB limit. Please upload a smaller PDF.")
|
| 32 |
+
return
|
| 33 |
|
| 34 |
self.state = SessionState()
|
| 35 |
doc = fitz.open(pdf_file.name)
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
gr.Info("PDF processed successfully! You can now ask questions about the document.")
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
if os.path.exists(self.state.vector_store_path):
|
| 54 |
shutil.rmtree(self.state.vector_store_path)
|
| 55 |
gr.Error(f"An error occurred: {str(e)}")
|
|
|
|
| 56 |
|
| 57 |
def chat_with_pdf(self, message, history):
|
| 58 |
if not self.state.is_db_ready():
|
|
|
|
| 124 |
visible=False
|
| 125 |
)
|
| 126 |
|
| 127 |
+
def process_and_show_chat(file):
|
| 128 |
+
chatbot.process_pdf(file)
|
| 129 |
+
return gr.update(visible=True), gr.update(interactive=False)
|
| 130 |
|
| 131 |
file_upload_input.upload(
|
| 132 |
+
fn=process_and_show_chat,
|
| 133 |
inputs=[file_upload_input],
|
| 134 |
+
outputs=[chat_interface, file_upload_input]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
)
|
| 136 |
|
| 137 |
demo.launch()
|