File size: 2,076 Bytes
225be25
 
 
 
 
 
 
 
 
 
 
 
 
6a58fd5
 
 
 
 
 
 
 
 
 
225be25
 
 
 
 
6a58fd5
 
 
 
 
 
 
 
 
225be25
 
 
 
 
6a58fd5
 
 
 
 
 
225be25
6a58fd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225be25
 
 
 
 
 
6a58fd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Document Format Converter
emoji: 🙊
colorFrom: green
colorTo: indigo
sdk: gradio
sdk_version: 5.13.2
app_file: app.py
pinned: false
license: apache-2.0
short_description: Upload document and select target format for conversion.
---

# Document Format Converter

Upload document and select target format for conversion.

## Web Interface

This application provides a web interface for document conversion. Simply upload your document and select the target format.

## API Endpoints

The application provides API endpoints for programmatic access. **API key authentication is required.**

### Authentication

All API requests require an API key to be sent in the `X-API-Key` header.

### 1. DOCX to JSON Conversion

```python
import requests

# URL of the API endpoint
url = "https://huggingface.co/spaces/ObiJuanCodenobi/docgen/api/docx-to-json"

# API key for authentication
headers = {
    'X-API-Key': 'YOUR_API_KEY'
}

# Prepare the file for upload
files = {
    'file': ('document.docx', open('path/to/your/document.docx', 'rb'), 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
}

# Send the request
response = requests.post(url, files=files, headers=headers)

# Get the JSON result
if response.status_code == 200:
    json_data = response.json()
    print(json_data)
else:
    print(f"Error: {response.status_code}, {response.text}")
```

### 2. JSON to DOCX Conversion

```python
import requests

# URL of the API endpoint
url = "https://huggingface.co/spaces/ObiJuanCodenobi/docgen/api/json-to-docx"

# API key for authentication
headers = {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
}

# Your JSON document data
json_data = {
    # Your document structure here
}

# Send the request
response = requests.post(url, json=json_data, headers=headers)

# Save the DOCX file
if response.status_code == 200:
    with open('converted.docx', 'wb') as f:
        f.write(response.content)
    print("DOCX file saved as 'converted.docx'")
else:
    print(f"Error: {response.status_code}, {response.text}")
```