Skip to content

Commit 0f219ae

Browse files
committed
fix upload bugs and lint
1 parent cf49db8 commit 0f219ae

10 files changed

Lines changed: 323 additions & 216 deletions

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,3 @@ All notable changes to DeepCode will be documented in this file.
7171
## [1.0.5] - Previous Release
7272

7373
See previous releases for earlier changes.
74-

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ fastapi>=0.104.0
1010
google-genai
1111
mcp-agent
1212
mcp-server-git
13-
openapi
1413
nest_asyncio
1514
openai
15+
openapi
1616
pathlib2
1717
pydantic-settings>=2.0.0
1818
PyPDF2>=2.0.0

tools/pdf_converter.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import platform
2121
import os
2222
from pathlib import Path
23-
from typing import Union, Optional, Dict, Any, List
23+
from typing import Union, Optional, Dict, Any
2424

2525

2626
class PDFConverter:
@@ -45,33 +45,37 @@ def __init__(self) -> None:
4545
def find_libreoffice_windows() -> Optional[str]:
4646
"""
4747
Find LibreOffice installation on Windows.
48-
48+
4949
Returns:
5050
Path to soffice.exe if found, None otherwise
5151
"""
5252
if platform.system() != "Windows":
5353
return None
54-
54+
5555
# Common LibreOffice installation paths on Windows
5656
possible_paths = [
5757
r"C:\Program Files\LibreOffice\program\soffice.exe",
5858
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
5959
]
60-
60+
6161
# Also check PROGRAMFILES environment variables
6262
program_files = os.environ.get("PROGRAMFILES")
6363
program_files_x86 = os.environ.get("PROGRAMFILES(X86)")
64-
64+
6565
if program_files:
66-
possible_paths.append(os.path.join(program_files, "LibreOffice", "program", "soffice.exe"))
66+
possible_paths.append(
67+
os.path.join(program_files, "LibreOffice", "program", "soffice.exe")
68+
)
6769
if program_files_x86:
68-
possible_paths.append(os.path.join(program_files_x86, "LibreOffice", "program", "soffice.exe"))
69-
70+
possible_paths.append(
71+
os.path.join(program_files_x86, "LibreOffice", "program", "soffice.exe")
72+
)
73+
7074
# Check each path
7175
for path in possible_paths:
7276
if os.path.exists(path):
7377
return path
74-
78+
7579
return None
7680

7781
@staticmethod
@@ -103,9 +107,10 @@ def convert_office_to_pdf(
103107
else:
104108
# Generate unique folder name with timestamp to avoid conflicts
105109
import time
110+
106111
timestamp = int(time.time())
107112
folder_name = f"paper_{timestamp}"
108-
113+
109114
# Save to workspace instead of temp directory
110115
workspace_base = Path(os.getcwd()) / "deepcode_lab" / "papers"
111116
workspace_base.mkdir(parents=True, exist_ok=True)
@@ -199,7 +204,7 @@ def convert_office_to_pdf(
199204

200205
# Use the working LibreOffice command first, then try alternatives if it fails
201206
commands_to_try = [working_libreoffice_cmd]
202-
207+
203208
# Add alternative commands based on what was found
204209
if platform.system() == "Windows" and working_libreoffice_cmd:
205210
# If we're using the full Windows path, also try standard commands
@@ -293,7 +298,7 @@ def convert_office_to_pdf(
293298
# Copy PDF to final output directory
294299
final_pdf_path = base_output_dir / f"{name_without_suff}.pdf"
295300
shutil.copy2(pdf_path, final_pdf_path)
296-
301+
297302
print(f"✅ PDF saved to: {final_pdf_path}")
298303
print(f" File size: {final_pdf_path.stat().st_size} bytes")
299304
print(f" Parent folder: {base_output_dir}")
@@ -353,9 +358,10 @@ def convert_text_to_pdf(
353358
else:
354359
# Generate unique folder name with timestamp to avoid conflicts
355360
import time
361+
356362
timestamp = int(time.time())
357363
folder_name = f"paper_{timestamp}"
358-
364+
359365
# Save to workspace instead of temp directory
360366
workspace_base = Path(os.getcwd()) / "deepcode_lab" / "papers"
361367
workspace_base.mkdir(parents=True, exist_ok=True)
@@ -516,7 +522,7 @@ def convert_text_to_pdf(
516522
print(f"✅ PDF saved to: {pdf_path}")
517523
print(f" File size: {pdf_path.stat().st_size} bytes")
518524
print(f" Parent folder: {base_output_dir}")
519-
525+
520526
return pdf_path
521527

522528
except Exception as e:
@@ -634,11 +640,19 @@ def check_dependencies(self) -> dict:
634640
try:
635641
subprocess.run(["libreoffice", "--version"], **subprocess_kwargs)
636642
results["libreoffice"] = True
637-
except (subprocess.CalledProcessError, FileNotFoundError, subprocess.TimeoutExpired):
643+
except (
644+
subprocess.CalledProcessError,
645+
FileNotFoundError,
646+
subprocess.TimeoutExpired,
647+
):
638648
try:
639649
subprocess.run(["soffice", "--version"], **subprocess_kwargs)
640650
results["libreoffice"] = True
641-
except (subprocess.CalledProcessError, FileNotFoundError, subprocess.TimeoutExpired):
651+
except (
652+
subprocess.CalledProcessError,
653+
FileNotFoundError,
654+
subprocess.TimeoutExpired,
655+
):
642656
pass
643657
except Exception:
644658
# If any unexpected error occurs during LibreOffice check, silently pass

ui/handlers.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@
2020
# Global abort flag
2121
_abort_requested = False
2222

23+
2324
def set_abort_requested(value: bool = True):
2425
"""Set the global abort flag"""
2526
global _abort_requested
2627
_abort_requested = value
2728
if value:
2829
print("🛑 Abort requested by user")
2930

31+
3032
def is_abort_requested() -> bool:
3133
"""Check if abort has been requested"""
3234
return _abort_requested
3335

36+
3437
def reset_abort_flag():
3538
"""Reset the abort flag"""
3639
global _abort_requested
3740
_abort_requested = False
3841

42+
3943
# Import necessary modules
4044
from mcp_agent.app import MCPApp
4145
from workflows.agent_orchestration_engine import (
@@ -141,7 +145,7 @@ async def process_input_async(
141145
# Check for abort before starting
142146
if is_abort_requested():
143147
return {"status": "aborted", "message": "Process aborted by user"}
144-
148+
145149
# Choose pipeline based on input type
146150
if input_type == "chat":
147151
# Use chat-based planning pipeline for user requirements
@@ -467,20 +471,20 @@ def handle_processing_workflow(
467471
# Define enhanced progress callback function
468472
def update_progress(progress: int, message: str, error: str = None):
469473
nonlocal current_step
470-
474+
471475
# Check for abort request
472476
if is_abort_requested():
473477
st.error("🛑 Process aborted by user")
474478
return
475479

476480
# Update progress bar
477481
progress_bar.progress(progress)
478-
482+
479483
# Display error if present
480484
if error:
481485
st.error(f"❌ Error: {error}")
482486
print(f"❌ Error: {error}")
483-
487+
484488
# Update status with timestamp
485489
timestamp = datetime.now().strftime("%H:%M:%S")
486490
status_text.markdown(f"**[{timestamp}]** {message}")
@@ -523,7 +527,7 @@ def update_progress(progress: int, message: str, error: str = None):
523527
# Check for abort before starting
524528
if is_abort_requested():
525529
return {"status": "aborted", "message": "Process aborted by user"}
526-
530+
527531
try:
528532
# First try using simple async processing method
529533
result = run_async_task_simple(
@@ -536,7 +540,7 @@ def update_progress(progress: int, message: str, error: str = None):
536540
st.warning(error_msg)
537541
print(f"⚠️ {error_msg}")
538542
update_progress(0, "Retrying with fallback method...", error_msg)
539-
543+
540544
# Fallback method: use original thread pool method
541545
try:
542546
result = run_async_task(
@@ -983,7 +987,7 @@ def handle_start_processing_button(input_source: str, input_type: str):
983987

984988
# Clean up system resources
985989
cleanup_resources()
986-
990+
987991
# Reset abort flag
988992
reset_abort_flag()
989993

utils/file_processor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@ async def read_file_content(file_path: str) -> str:
194194
# Try to convert PDF to markdown automatically
195195
try:
196196
from tools.pdf_downloader import SimplePdfConverter
197+
197198
converter = SimplePdfConverter()
198199
conversion_result = converter.convert_pdf_to_markdown(file_path)
199-
200+
200201
if conversion_result["success"]:
201202
# Use the converted markdown file instead
202203
file_path = conversion_result["output_file"]
203204
else:
204-
raise IOError(f"PDF conversion failed: {conversion_result['error']}")
205+
raise IOError(
206+
f"PDF conversion failed: {conversion_result['error']}"
207+
)
205208
except Exception as conv_error:
206209
raise IOError(
207210
f"File {file_path} is a PDF file, not a text file. PDF conversion failed: {str(conv_error)}"

0 commit comments

Comments
 (0)