AnseMin commited on
Commit
bdc060b
Β·
1 Parent(s): 66f3c4d

Removing chat with document feature

Browse files
Files changed (4) hide show
  1. README.md +2 -22
  2. requirements.txt +0 -1
  3. src/services/docling_chat.py +0 -29
  4. src/ui/ui.py +35 -62
README.md CHANGED
@@ -137,13 +137,6 @@ build:
137
  6. Navigate through pages using the navigation buttons for multi-page documents
138
  7. Download the converted content in your selected format
139
 
140
- ### Document Chat
141
- 1. After converting a document, switch to the "Chat with Document" tab
142
- 2. Type your questions about the document content
143
- 3. The AI will analyze the document and provide context-aware responses
144
- 4. Use the conversation history to track your Q&A session
145
- 5. Click "Clear" to start a new conversation
146
-
147
  ## Troubleshooting
148
 
149
  ### OCR Issues
@@ -201,20 +194,7 @@ markit/
201
  β”‚ β”‚ β”œβ”€β”€ __init__.py # Package initialization
202
  β”‚ β”‚ └── ui.py # Gradio UI implementation
203
  β”‚ └── services/ # External services
204
- β”‚ β”œβ”€β”€ __init__.py # Package initialization
205
- β”‚ └── docling_chat.py # Chat service
206
  └── tests/ # Tests
207
  └── __init__.py # Package initialization
208
- ```
209
-
210
- ### Adding a New Parser
211
- 1. Create a new parser class implementing the `DocumentParser` interface
212
- 2. Register the parser with the `ParserRegistry`
213
- 3. Implement the required methods: `get_name()`, `get_supported_ocr_methods()`, and `parse()`
214
- 4. Add your parser to the imports in `src/parsers/__init__.py`
215
-
216
- ## Contributing
217
- Contributions are welcome! Please feel free to submit a Pull Request.
218
-
219
- ## License
220
- This project is open source and available under the MIT License.
 
137
  6. Navigate through pages using the navigation buttons for multi-page documents
138
  7. Download the converted content in your selected format
139
 
 
 
 
 
 
 
 
140
  ## Troubleshooting
141
 
142
  ### OCR Issues
 
194
  β”‚ β”‚ β”œβ”€β”€ __init__.py # Package initialization
195
  β”‚ β”‚ └── ui.py # Gradio UI implementation
196
  β”‚ └── services/ # External services
197
+ β”‚ └── __init__.py # Package initialization
 
198
  └── tests/ # Tests
199
  └── __init__.py # Package initialization
200
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -4,7 +4,6 @@ grpcio-status==1.70.0
4
  markdown==3.7
5
  marker-pdf==1.3.5
6
  multiprocess==0.70.16
7
- openai==1.61.1
8
  pipdeptree==2.25.0
9
  pytesseract==0.3.13
10
  semchunk==2.2.2
 
4
  markdown==3.7
5
  marker-pdf==1.3.5
6
  multiprocess==0.70.16
 
7
  pipdeptree==2.25.0
8
  pytesseract==0.3.13
9
  semchunk==2.2.2
src/services/docling_chat.py DELETED
@@ -1,29 +0,0 @@
1
- import openai
2
- import os
3
-
4
- # Load API key from environment variable
5
- openai.api_key = os.getenv("OPENAI_API_KEY")
6
-
7
- # Check if API key is available and print a message if not
8
- if not openai.api_key:
9
- print("Warning: OPENAI_API_KEY environment variable not found. Chat functionality may not work.")
10
-
11
- def chat_with_document(message, history, document_text_state):
12
- history = history or []
13
- history.append({"role": "user", "content": message})
14
-
15
- context = f"Document: {document_text_state}\n\nUser: {message}"
16
-
17
- # Add error handling for API calls
18
- try:
19
- response = openai.chat.completions.create(
20
- model="gpt-4o-2024-08-06",
21
- messages=[{"role": "system", "content": context}] + history
22
- )
23
- reply = response.choices[0].message.content
24
- except Exception as e:
25
- reply = f"Error: Could not generate response. Please check your OpenAI API key. Details: {str(e)}"
26
- print(f"OpenAI API error: {str(e)}")
27
-
28
- history.append({"role": "assistant", "content": reply})
29
- return history, history
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/ui/ui.py CHANGED
@@ -5,7 +5,6 @@ import time
5
  import logging
6
  from pathlib import Path
7
  from src.core.converter import convert_file, set_cancellation_flag, is_conversion_in_progress
8
- from src.services.docling_chat import chat_with_document
9
  from src.parsers.parser_registry import ParserRegistry
10
 
11
  # Configure logging
@@ -169,52 +168,44 @@ def create_ui():
169
  # State to store the output format (fixed to Markdown)
170
  output_format_state = gr.State("Markdown")
171
 
172
- with gr.Tabs():
173
- with gr.Tab("Upload and Convert"):
174
- # File input first
175
- file_input = gr.File(label="Upload PDF", type="filepath")
176
-
177
- # Provider and OCR options below the file input
178
- with gr.Row(elem_classes=["provider-options-row"]):
179
- with gr.Column(scale=1):
180
- parser_names = ParserRegistry.get_parser_names()
181
- default_parser = parser_names[0] if parser_names else "PyPdfium"
182
-
183
- provider_dropdown = gr.Dropdown(
184
- label="Provider",
185
- choices=parser_names,
186
- value=default_parser,
187
- interactive=True
188
- )
189
- with gr.Column(scale=1):
190
- default_ocr_options = ParserRegistry.get_ocr_options(default_parser)
191
- default_ocr = default_ocr_options[0] if default_ocr_options else "No OCR"
192
-
193
- ocr_dropdown = gr.Dropdown(
194
- label="OCR Options",
195
- choices=default_ocr_options,
196
- value=default_ocr,
197
- interactive=True
198
- )
199
 
200
- # Simple output container with just one scrollbar
201
- file_display = gr.HTML(
202
- value="<div class='output-container'></div>",
203
- label="Converted Content"
 
204
  )
 
 
 
205
 
206
- file_download = gr.File(label="Download File")
207
-
208
- # Processing controls row
209
- with gr.Row(elem_classes=["processing-controls"]):
210
- convert_button = gr.Button("Convert", variant="primary")
211
- cancel_button = gr.Button("Cancel", variant="stop", visible=False)
212
-
213
- with gr.Tab("Chat with Document"):
214
- document_text_state = gr.State("")
215
- chatbot = gr.Chatbot(label="Chat", type="messages")
216
- text_input = gr.Textbox(placeholder="Type here...")
217
- clear_btn = gr.Button("Clear")
 
 
 
 
 
 
 
218
 
219
  # Event handlers
220
  provider_dropdown.change(
@@ -269,24 +260,6 @@ def create_ui():
269
  queue=False # Execute immediately
270
  )
271
 
272
- file_display.change(
273
- lambda text: text,
274
- inputs=[file_display],
275
- outputs=[document_text_state]
276
- )
277
-
278
- text_input.submit(
279
- fn=chat_with_document,
280
- inputs=[text_input, chatbot, document_text_state],
281
- outputs=[chatbot, chatbot]
282
- )
283
-
284
- clear_btn.click(
285
- lambda: ([], []),
286
- None,
287
- [chatbot, chatbot]
288
- )
289
-
290
  return demo
291
 
292
 
 
5
  import logging
6
  from pathlib import Path
7
  from src.core.converter import convert_file, set_cancellation_flag, is_conversion_in_progress
 
8
  from src.parsers.parser_registry import ParserRegistry
9
 
10
  # Configure logging
 
168
  # State to store the output format (fixed to Markdown)
169
  output_format_state = gr.State("Markdown")
170
 
171
+ # File input first
172
+ file_input = gr.File(label="Upload PDF", type="filepath")
173
+
174
+ # Provider and OCR options below the file input
175
+ with gr.Row(elem_classes=["provider-options-row"]):
176
+ with gr.Column(scale=1):
177
+ parser_names = ParserRegistry.get_parser_names()
178
+ default_parser = parser_names[0] if parser_names else "PyPdfium"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
+ provider_dropdown = gr.Dropdown(
181
+ label="Provider",
182
+ choices=parser_names,
183
+ value=default_parser,
184
+ interactive=True
185
  )
186
+ with gr.Column(scale=1):
187
+ default_ocr_options = ParserRegistry.get_ocr_options(default_parser)
188
+ default_ocr = default_ocr_options[0] if default_ocr_options else "No OCR"
189
 
190
+ ocr_dropdown = gr.Dropdown(
191
+ label="OCR Options",
192
+ choices=default_ocr_options,
193
+ value=default_ocr,
194
+ interactive=True
195
+ )
196
+
197
+ # Simple output container with just one scrollbar
198
+ file_display = gr.HTML(
199
+ value="<div class='output-container'></div>",
200
+ label="Converted Content"
201
+ )
202
+
203
+ file_download = gr.File(label="Download File")
204
+
205
+ # Processing controls row
206
+ with gr.Row(elem_classes=["processing-controls"]):
207
+ convert_button = gr.Button("Convert", variant="primary")
208
+ cancel_button = gr.Button("Cancel", variant="stop", visible=False)
209
 
210
  # Event handlers
211
  provider_dropdown.change(
 
260
  queue=False # Execute immediately
261
  )
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  return demo
264
 
265