Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,12 @@ async def root():
|
|
| 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 |
async with httpx.AsyncClient(timeout=60.0) as client:
|
|
@@ -36,7 +42,7 @@ async def pass_docs_html():
|
|
| 36 |
raise HTTPException(status_code=response.status_code, detail=f"Error: {str(e)}")
|
| 37 |
except httpx.RequestError as e:
|
| 38 |
raise HTTPException(status_code=500, detail=f"Network error: {str(e)}")
|
| 39 |
-
|
| 40 |
|
| 41 |
@app.get("/eins/")
|
| 42 |
async def proxy_request(request: Request):
|
|
@@ -66,44 +72,3 @@ async def proxy_request(request: Request):
|
|
| 66 |
if __name__ == "__main__":
|
| 67 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
"""
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
import os
|
| 75 |
-
import requests
|
| 76 |
-
import json
|
| 77 |
-
|
| 78 |
-
# Access the secret environment variable
|
| 79 |
-
space_token = os.environ.get('api_key')
|
| 80 |
-
api_url = "https://givingtuesday-annotated-990-data.hf.space/eins"
|
| 81 |
-
headers = {
|
| 82 |
-
"Authorization": f"Bearer {space_token}",
|
| 83 |
-
"Content-Type": "application/json"
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
def call_private_api(kwargs):
|
| 89 |
-
# 'kwargs' should be a dict matching the input components of the target space
|
| 90 |
-
#payload = {
|
| 91 |
-
# "data": [input_data],
|
| 92 |
-
# You can add other kwargs to the payload here if needed by the specific API
|
| 93 |
-
# "kwargs": {"some_param": "some_value"}
|
| 94 |
-
#}
|
| 95 |
-
print(kwargs)
|
| 96 |
-
response = requests.post(api_url, headers=headers, json=kwargs)
|
| 97 |
-
return response.json()
|
| 98 |
-
|
| 99 |
-
import gradio as gr
|
| 100 |
-
# Example usage within a Gradio interface in the public space
|
| 101 |
-
with gr.Blocks() as demo:
|
| 102 |
-
text_input = gr.Textbox(label="Input")
|
| 103 |
-
text_output = gr.Textbox(label="Response")
|
| 104 |
-
submit_btn = gr.Button("Get eins")
|
| 105 |
-
submit_btn.click(fn=call_private_api, inputs=text_input, outputs=text_output)
|
| 106 |
-
|
| 107 |
-
demo.launch()
|
| 108 |
-
|
| 109 |
-
"""
|
|
|
|
| 24 |
|
| 25 |
@app.get('/docs/')
|
| 26 |
async def pass_docs_html():
|
| 27 |
+
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 28 |
+
response = await client.get(f"{api_url}/docs#/default/get_eins_eins__get", headers=headers)
|
| 29 |
+
html_content = response.text
|
| 30 |
+
return HTMLResponse(content=html_content, status_code=200)
|
| 31 |
+
|
| 32 |
+
"""
|
| 33 |
# Use httpx to make an asynchronous GET request to the private API
|
| 34 |
try:
|
| 35 |
async with httpx.AsyncClient(timeout=60.0) as client:
|
|
|
|
| 42 |
raise HTTPException(status_code=response.status_code, detail=f"Error: {str(e)}")
|
| 43 |
except httpx.RequestError as e:
|
| 44 |
raise HTTPException(status_code=500, detail=f"Network error: {str(e)}")
|
| 45 |
+
"""
|
| 46 |
|
| 47 |
@app.get("/eins/")
|
| 48 |
async def proxy_request(request: Request):
|
|
|
|
| 72 |
if __name__ == "__main__":
|
| 73 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|