Spaces:
Running
Running
Commit
·
2f87aed
1
Parent(s):
9b5a195
Add Hello World API test
Browse files- Dockerfile +21 -0
- app.py +70 -0
- requirements.txt +4 -0
Dockerfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
# Create non-root user
|
| 4 |
+
RUN useradd -m -u 1000 user
|
| 5 |
+
USER user
|
| 6 |
+
ENV HOME=/home/user \
|
| 7 |
+
PATH=/home/user/.local/bin:$PATH
|
| 8 |
+
|
| 9 |
+
WORKDIR $HOME/app
|
| 10 |
+
|
| 11 |
+
# Copy and install requirements
|
| 12 |
+
COPY --chown=user:user requirements.txt .
|
| 13 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Copy application code
|
| 16 |
+
COPY --chown=user:user app.py .
|
| 17 |
+
|
| 18 |
+
EXPOSE 7860
|
| 19 |
+
|
| 20 |
+
# Start the application
|
| 21 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
@app.get("/")
|
| 8 |
+
async def root():
|
| 9 |
+
"""Simple hello world endpoint"""
|
| 10 |
+
return {
|
| 11 |
+
"message": "Hello World from MinerU PDF Converter!",
|
| 12 |
+
"status": "running",
|
| 13 |
+
"environment": os.environ.get("SPACE_ID", "local")
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
@app.get("/health")
|
| 17 |
+
async def health_check():
|
| 18 |
+
"""Health check endpoint"""
|
| 19 |
+
return {"status": "healthy", "service": "pdf2md"}
|
| 20 |
+
|
| 21 |
+
@app.get("/test", response_class=HTMLResponse)
|
| 22 |
+
async def test_page():
|
| 23 |
+
"""Simple HTML test page"""
|
| 24 |
+
return """
|
| 25 |
+
<html>
|
| 26 |
+
<head>
|
| 27 |
+
<title>PDF to Markdown - Test</title>
|
| 28 |
+
<style>
|
| 29 |
+
body {
|
| 30 |
+
font-family: Arial, sans-serif;
|
| 31 |
+
max-width: 800px;
|
| 32 |
+
margin: 0 auto;
|
| 33 |
+
padding: 20px;
|
| 34 |
+
}
|
| 35 |
+
.status {
|
| 36 |
+
background: #e8f5e9;
|
| 37 |
+
padding: 10px;
|
| 38 |
+
border-radius: 5px;
|
| 39 |
+
margin: 20px 0;
|
| 40 |
+
}
|
| 41 |
+
</style>
|
| 42 |
+
</head>
|
| 43 |
+
<body>
|
| 44 |
+
<h1>PDF to Markdown Converter</h1>
|
| 45 |
+
<div class="status">
|
| 46 |
+
✅ Service is running!
|
| 47 |
+
</div>
|
| 48 |
+
<p>This is a test deployment. Full functionality coming soon.</p>
|
| 49 |
+
<p>
|
| 50 |
+
<a href="/docs">API Documentation</a> |
|
| 51 |
+
<a href="/health">Health Check</a>
|
| 52 |
+
</p>
|
| 53 |
+
</body>
|
| 54 |
+
</html>
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
@app.get("/api/info")
|
| 58 |
+
async def api_info():
|
| 59 |
+
"""API information endpoint"""
|
| 60 |
+
return {
|
| 61 |
+
"name": "PDF to Markdown Converter API",
|
| 62 |
+
"version": "0.1.0",
|
| 63 |
+
"endpoints": {
|
| 64 |
+
"/": "Main endpoint",
|
| 65 |
+
"/health": "Health check",
|
| 66 |
+
"/test": "Test HTML page",
|
| 67 |
+
"/docs": "FastAPI automatic documentation",
|
| 68 |
+
"/api/info": "This endpoint"
|
| 69 |
+
}
|
| 70 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.104.1
|
| 2 |
+
uvicorn==0.24.0
|
| 3 |
+
python-multipart==0.0.6
|
| 4 |
+
aiofiles==23.2.1
|