Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
from fastapi import FastAPI, Request, HTTPException
|
|
|
|
| 3 |
import httpx
|
| 4 |
from urllib.parse import urlencode
|
| 5 |
import uvicorn
|
|
@@ -17,11 +18,27 @@ headers = {
|
|
| 17 |
"Content-Type": "application/json"
|
| 18 |
}
|
| 19 |
|
| 20 |
-
# /docs is auto-generated
|
| 21 |
@app.get('/')
|
| 22 |
async def root():
|
| 23 |
return {"message": "990 API v1.0 running -- visit https://givingtuesday-annotated-990.hf.space/docs for usage"}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
@app.get("/eins/")
|
| 26 |
async def proxy_request(request: Request):
|
| 27 |
# Capture all query parameters from the incoming request
|
|
|
|
| 1 |
import os
|
| 2 |
from fastapi import FastAPI, Request, HTTPException
|
| 3 |
+
from fastapi.responses import HTMLResponse
|
| 4 |
import httpx
|
| 5 |
from urllib.parse import urlencode
|
| 6 |
import uvicorn
|
|
|
|
| 18 |
"Content-Type": "application/json"
|
| 19 |
}
|
| 20 |
|
|
|
|
| 21 |
@app.get('/')
|
| 22 |
async def root():
|
| 23 |
return {"message": "990 API v1.0 running -- visit https://givingtuesday-annotated-990.hf.space/docs for usage"}
|
| 24 |
|
| 25 |
+
@app.get('/docs/')
|
| 26 |
+
async def pass_docs_html():
|
| 27 |
+
# Use httpx to make an asynchronous GET request to the private API
|
| 28 |
+
try:
|
| 29 |
+
print('params', private_api_url)
|
| 30 |
+
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 31 |
+
response = await client.get(f"{api_url}/docs/", headers=headers)
|
| 32 |
+
response.raise_for_status() # Raise an exception for 4xx/5xx responses
|
| 33 |
+
html_content = response.text
|
| 34 |
+
return HTMLResponse(content=html_content, status_code=200)
|
| 35 |
+
|
| 36 |
+
except httpx.HTTPStatusError as e:
|
| 37 |
+
raise HTTPException(status_code=response.status_code, detail=f"Error: {str(e)}")
|
| 38 |
+
except httpx.RequestError as e:
|
| 39 |
+
raise HTTPException(status_code=500, detail=f"Network error: {str(e)}")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
@app.get("/eins/")
|
| 43 |
async def proxy_request(request: Request):
|
| 44 |
# Capture all query parameters from the incoming request
|