File size: 6,206 Bytes
217b481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API Documentation - PDF Layout Extractor</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .method-badge {
            display: inline-block;
            padding: 0.25em 0.6em;
            font-size: 0.75em;
            font-weight: 700;
            border-radius: 0.25rem;
            margin-right: 0.5rem;
        }
        .method-get { background-color: #28a745; color: white; }
        .method-post { background-color: #007bff; color: white; }
        .method-delete { background-color: #dc3545; color: white; }
        code {
            background-color: #f8f9fa;
            padding: 0.2em 0.4em;
            border-radius: 0.25rem;
            font-size: 0.9em;
        }
        .endpoint-card {
            margin-bottom: 1rem;
            transition: transform 0.2s;
        }
        .endpoint-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        pre {
            margin: 0;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <i class="fas fa-file-pdf me-2"></i>
                PDF Layout Extractor - API Docs
            </a>
            <div>
                <a href="/" class="btn btn-light">
                    <i class="fas fa-arrow-left me-1"></i>Back to App
                </a>
            </div>
        </div>
    </nav>

    <div class="container mt-4 mb-5">
        <h1 class="mb-4"><i class="fas fa-book me-2"></i>API Documentation</h1>
        
        <div class="alert alert-info">
            <strong><i class="fas fa-info-circle me-2"></i>Base URL:</strong> <code>{{ base_url }}</code>
        </div>

        <div class="row">
            <div class="col-12">
                {% for route in routes %}
                <div class="card endpoint-card shadow-sm">
                    <div class="card-body">
                        <h5 class="card-title">
                            {% for method in route.methods.split(',') %}
                            <span class="method-badge method-{{ method.lower() }}">{{ method }}</span>
                            {% endfor %}
                            <code>{{ route.endpoint }}</code>
                        </h5>
                        <p class="card-text text-muted">{{ route.description }}</p>
                        <div class="mt-2">
                            <strong>Example Request:</strong>
                            <pre class="bg-light p-2 rounded mt-2"><code>{% set method = route.methods.split(',')[0] %}{{ method }} {{ base_url }}{{ route.endpoint }}</code></pre>
                        </div>
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>

        <div class="mt-5">
            <h2><i class="fas fa-code me-2"></i>Quick Examples</h2>
            <div class="card shadow-sm">
                <div class="card-body">
                    <h5>Python Example</h5>
                    <pre class="bg-light p-3 rounded"><code>import requests
import time

# Get device info
response = requests.get('{{ base_url }}/api/device-info')
print(response.json())

# Upload a PDF
files = {'files[]': open('document.pdf', 'rb')}
data = {'extraction_mode': 'both'}  # or 'images' or 'markdown'
response = requests.post('{{ base_url }}/api/upload', files=files, data=data)
task_id = response.json()['task_id']

# Check progress
while True:
    progress = requests.get(f'{{ base_url }}/api/progress/{task_id}').json()
    print(f"Progress: {progress['progress']}% - {progress['message']}")
    if progress['status'] == 'completed':
        break
    time.sleep(0.5)

# Get results
results = progress['results']
for result in results:
    print(f"Processed: {result['filename']}")
    print(f"  Figures: {result['figures_count']}")
    print(f"  Tables: {result['tables_count']}")</code></pre>
                </div>
            </div>

            <div class="card shadow-sm mt-3">
                <div class="card-body">
                    <h5>cURL Example</h5>
                    <pre class="bg-light p-3 rounded"><code># Get device info
curl {{ base_url }}/api/device-info

# Upload a PDF
curl -X POST {{ base_url }}/api/upload \
  -F "files[]=@document.pdf" \
  -F "extraction_mode=both"

# Check progress (replace TASK_ID)
curl {{ base_url }}/api/progress/TASK_ID

# List processed PDFs
curl {{ base_url }}/api/pdf-list</code></pre>
                </div>
            </div>
        </div>

        <div class="mt-5">
            <h2><i class="fas fa-question-circle me-2"></i>API Endpoints Overview</h2>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Method</th>
                            <th>Endpoint</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for route in routes %}
                        <tr>
                            <td>
                                {% for method in route.methods.split(',') %}
                                <span class="method-badge method-{{ method.lower() }}">{{ method }}</span>
                                {% endfor %}
                            </td>
                            <td><code>{{ route.endpoint }}</code></td>
                            <td>{{ route.description }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>