Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bugs, improved compatibility, adjusted backend, and enhanced UI #264

Merged
merged 6 commits into from
Jan 7, 2025
Merged
8 changes: 5 additions & 3 deletions server/app/routes/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import aiohttp
from pathlib import Path
from urllib.parse import urljoin
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest, AnalyzeResult, DocumentContentFormat
from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.core.credentials import AzureKeyCredential
Expand Down Expand Up @@ -55,6 +56,7 @@ async def convert_documents(
custom_docling_url: Optional[str] = Header(None)
):
use_docetl_server = use_docetl_server.lower() == "true" # TODO: make this a boolean


# If custom Docling URL is provided, forward the request there
if custom_docling_url:
Expand All @@ -78,18 +80,18 @@ async def convert_documents(
"output_html": False,
"do_ocr": True,
"do_table_structure": True,
"include_images": True
"include_images": False
}
}

async with session.post(
f"{custom_docling_url}/convert",
urljoin(custom_docling_url, 'convert'),
json=payload,
timeout=120
) as response:
if response.status == 200:
result = await response.json()
if result["status"] == "success":
if result["status"] in ("success", '4'):
results.append({
"filename": file.filename,
"markdown": result["document"]["markdown"]
Expand Down
3 changes: 2 additions & 1 deletion website/src/app/api/convertDocuments/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ export async function POST(request: NextRequest) {
if (azureEndpoint && azureKey) {
targetUrl = `${FASTAPI_URL}/api/azure-convert-documents`;
} else if (customDoclingUrl) {
targetUrl = `${customDoclingUrl}/convert`;
targetUrl = `${FASTAPI_URL}/api/convert-documents`;
} else {
targetUrl = `${FASTAPI_URL}/api/convert-documents${
conversionMethod === "docetl" ? "?use_docetl_server=true" : ""
}`;
}


// Forward the request to the appropriate backend
const response = await fetch(targetUrl, {
method: "POST",
Expand Down
55 changes: 26 additions & 29 deletions website/src/components/FileExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ export const FileExplorer: React.FC<FileExplorerProps> = ({
onValueChange={(value) =>
setConversionMethod(value as ConversionMethod)
}
className="mt-2 grid grid-cols-3 gap-2"
className="mt-2 grid grid-cols-4 gap-2"
>
<div className="flex flex-col space-y-1 p-2 rounded-md transition-colors hover:bg-gray-50 cursor-pointer border border-gray-100">
<div className="flex items-start space-x-2.5">
Expand Down Expand Up @@ -876,11 +876,11 @@ export const FileExplorer: React.FC<FileExplorerProps> = ({

<div
className={`
border-2 border-dashed rounded-lg transition-colors relative flex-shrink-0
border border-dashed rounded-lg transition-colors relative flex-shrink-0
${
selectedFiles && selectedFiles.length > 0
? "border-border bg-accent/50 p-6"
: "border-border p-8 hover:border-primary"
? "border-border bg-accent/50 p-3"
: "border-border p-3 hover:border-primary"
}
`}
onDragOver={(e) => {
Expand Down Expand Up @@ -931,33 +931,30 @@ export const FileExplorer: React.FC<FileExplorerProps> = ({
)}

<div className="text-center">
<Upload className="w-10 h-10 mx-auto text-gray-400 mb-4" />
<div className="space-y-2">
<p className="text-sm text-gray-600">
Drag and drop your documents here or
</p>
<label>
<input
type="file"
multiple
className="hidden"
accept={SUPPORTED_EXTENSIONS.join(",")}
onChange={(e) => {
if (e.target.files) {
handleFolderUpload(e.target.files);
}
}}
/>
<span className="text-sm text-primary hover:text-blue-600 cursor-pointer">
browse files
</span>
</label>
<p className="text-xs text-gray-500">
<Upload className="w-5 h-5 mx-auto text-gray-400 mb-1" />
<div className="flex flex-col items-center">
<div className="flex items-center text-sm text-gray-500">
<span>Drag and drop your documents here or</span>
<label className="ml-0.5">
<input
type="file"
multiple
className="hidden"
accept={SUPPORTED_EXTENSIONS.join(",")}
onChange={(e) => {
if (e.target.files) {
handleFolderUpload(e.target.files);
}
}}
/>
<span className="text-primary hover:text-blue-600 cursor-pointer">
browse files
</span>
</label>
</div>
<p className="mt-0.5 text-[10px] text-gray-400">
Supported formats: PDF, DOCX, DOC, TXT, HTML, PPTX, MD
</p>
<p className="text-xs text-gray-500">
Processing may take up to 2 minutes
</p>
</div>
</div>
</div>
Expand Down
Loading