Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -58,6 +58,36 @@ async def _():
|
|
58 |
async def _():
|
59 |
return RedirectResponse("/weather_mcp/.well-known/oauth-protected-resource")
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
@app.post("/register")
|
62 |
async def register_proxy(request: Request):
|
63 |
"""Forward requests to Hugging Face OAuth register endpoint"""
|
@@ -75,8 +105,6 @@ async def register_proxy(request: Request):
|
|
75 |
|
76 |
# Get request body if present
|
77 |
body = await request.body()
|
78 |
-
|
79 |
-
print("body", body)
|
80 |
|
81 |
# Forward the request
|
82 |
response = await client.request(
|
@@ -94,6 +122,8 @@ async def register_proxy(request: Request):
|
|
94 |
headers=dict(response.headers)
|
95 |
)
|
96 |
|
|
|
|
|
97 |
if __name__ == "__main__":
|
98 |
import uvicorn
|
99 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
58 |
async def _():
|
59 |
return RedirectResponse("/weather_mcp/.well-known/oauth-protected-resource")
|
60 |
|
61 |
+
@app.get("/authorize")
|
62 |
+
async def authorize_proxy(request: Request):
|
63 |
+
"""Forward GET requests to Hugging Face OAuth authorize endpoint"""
|
64 |
+
target_url = "https://huggingface.co/oauth/authorize"
|
65 |
+
|
66 |
+
async with httpx.AsyncClient() as client:
|
67 |
+
# Prepare the request data
|
68 |
+
headers = dict(request.headers)
|
69 |
+
# Remove host header to avoid conflicts
|
70 |
+
headers.pop("host", None)
|
71 |
+
|
72 |
+
# Get query parameters
|
73 |
+
query_params = str(request.url.query) if request.url.query else None
|
74 |
+
target_url_with_params = f"{target_url}?{query_params}" if query_params else target_url
|
75 |
+
|
76 |
+
# Forward the request
|
77 |
+
response = await client.request(
|
78 |
+
method=request.method,
|
79 |
+
url=target_url_with_params,
|
80 |
+
headers=headers,
|
81 |
+
follow_redirects=False
|
82 |
+
)
|
83 |
+
|
84 |
+
# Return the response with the same status code, headers, and content
|
85 |
+
return Response(
|
86 |
+
content=response.content,
|
87 |
+
status_code=response.status_code,
|
88 |
+
headers=dict(response.headers)
|
89 |
+
)
|
90 |
+
|
91 |
@app.post("/register")
|
92 |
async def register_proxy(request: Request):
|
93 |
"""Forward requests to Hugging Face OAuth register endpoint"""
|
|
|
105 |
|
106 |
# Get request body if present
|
107 |
body = await request.body()
|
|
|
|
|
108 |
|
109 |
# Forward the request
|
110 |
response = await client.request(
|
|
|
122 |
headers=dict(response.headers)
|
123 |
)
|
124 |
|
125 |
+
|
126 |
+
|
127 |
if __name__ == "__main__":
|
128 |
import uvicorn
|
129 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|