Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions docstrange/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def main():

# Start web interface
docstrange web # Start web interface at http://localhost:8000

docstrange web --root-path /docstrange # Start at http://localhost:8000/docstrange

# Convert a PDF to markdown (default cloud mode)
docstrange document.pdf

Expand Down Expand Up @@ -338,7 +339,13 @@ def main():
action="store_true",
help="Clear cached authentication credentials"
)


parser.add_argument(
"--root-path",
default="",
help="Root path for the web server (e.g., '/docstrange'). Only used with 'web' command."
)

args = parser.parse_args()

# Handle version flag
Expand Down Expand Up @@ -368,9 +375,10 @@ def main():
try:
from .web_app import run_web_app
print("Starting DocStrange web interface...")
print("Open your browser and go to: http://localhost:8000")
base_url = f"http://localhost:8000{args.root_path}" if args.root_path else "http://localhost:8000"
print(f"Open your browser and go to: {base_url}")
print("Press Ctrl+C to stop the server")
run_web_app(host='0.0.0.0', port=8000, debug=False)
run_web_app(host='0.0.0.0', port=8000, debug=False, root_path=args.root_path)
return 0
except ImportError:
print("❌ Web interface not available. Install Flask: pip install Flask", file=sys.stderr)
Expand Down
6 changes: 4 additions & 2 deletions docstrange/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class DocStrangeApp {
constructor() {
this.selectedFile = null;
this.extractionResults = null;
// Get root path from global config, default to empty string
this.rootPath = window.APP_ROOT_PATH || '';
this.initializeApp();
}

Expand All @@ -14,7 +16,7 @@ class DocStrangeApp {

async loadSystemInfo() {
try {
const response = await fetch('/api/system-info');
const response = await fetch(`${this.rootPath}/api/system-info`);
if (response.ok) {
const systemInfo = await response.json();
this.updateProcessingModeOptions(systemInfo);
Expand Down Expand Up @@ -169,7 +171,7 @@ class DocStrangeApp {
// Use cloud processing mode by default
formData.append('processing_mode', 'cloud');

const response = await fetch('/api/extract', {
const response = await fetch(`${this.rootPath}/api/extract`, {
method: 'POST',
body: formData
});
Expand Down
13 changes: 10 additions & 3 deletions docstrange/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@
</style>
</head>
<body>
<!-- Root path configuration -->
<script>
// Global configuration for API paths
window.APP_ROOT_PATH = '{{ root_path }}';
</script>

<!-- Header -->
<header class="main-header">
<div class="header-logo-section">
Expand Down Expand Up @@ -996,12 +1002,13 @@ <h3>Error</h3>
formData.append('file', file);
formData.append('output_format', format === 'json' ? 'flat-json' : format);
formData.append('processing_mode', 'cloud');

// Show loading state
extractBtn.textContent = 'Processing...';
extractBtn.disabled = true;

fetch('/api/extract', {

const rootPath = window.APP_ROOT_PATH || '';
fetch(`${rootPath}/api/extract`, {
method: 'POST',
body: formData
})
Expand Down
27 changes: 21 additions & 6 deletions docstrange/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def create_extractor_with_mode(processing_mode):
@app.route('/')
def index():
"""Serve the main page."""
return render_template('index.html')
root_path = app.config.get('APPLICATION_ROOT', '')
return render_template('index.html', root_path=root_path)

@app.route('/static/<path:filename>')
def static_files(filename):
Expand Down Expand Up @@ -195,12 +196,24 @@ def get_system_info():

return jsonify(system_info)

def run_web_app(host='0.0.0.0', port=8000, debug=False):
"""Run the web application."""
def run_web_app(host='0.0.0.0', port=8000, debug=False, root_path=''):
"""Run the web application.

Args:
host: Host to bind to
port: Port to bind to
debug: Enable debug mode
root_path: Root path for the application (e.g., '/docstrange')
"""
# Configure root path if provided
if root_path:
app.config['APPLICATION_ROOT'] = root_path
print(f"📍 Application root path set to: {root_path}")

# Check GPU availability before starting the server
print("🔍 Checking GPU availability...")
gpu_available = check_gpu_availability()

if not gpu_available:
error_msg = (
"❌ GPU is not available! DocStrange requires GPU for optimal performance.\n"
Expand All @@ -214,11 +227,13 @@ def run_web_app(host='0.0.0.0', port=8000, debug=False):
)
print(error_msg)
raise RuntimeError("GPU is not available. DocStrange requires GPU for optimal performance.")

print("✅ GPU detected - proceeding with model download...")
print("🔄 Downloading models before starting the web interface...")
download_models()
print(f"✅ Starting docstrange web interface at http://{host}:{port}")

base_url = f"http://{host}:{port}{root_path}" if root_path else f"http://{host}:{port}"
print(f"✅ Starting docstrange web interface at {base_url}")
print("Press Ctrl+C to stop the server")
app.run(host=host, port=port, debug=debug)

Expand Down