docgen / README.md
Juan Palomino
Deploy Document Format Converter
225be25

A newer version of the Gradio SDK is available: 6.5.1

Upgrade
metadata
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

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

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}")