Created
April 17, 2024 10:58
-
-
Save gengen1988/f040a5c8004fea57eb651eb209455362 to your computer and use it in GitHub Desktop.
quick expose gradio python api to http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from typing import Annotated | |
from fastapi import Body, FastAPI | |
from gradio_client import Client | |
app = FastAPI() | |
@app.post("/gradio_proxy/{api_name}") | |
async def proxy(api_name: str, parameters: Annotated[dict, Body()]): | |
client = Client("http://127.0.0.1:7860") | |
job = client.submit(**parameters, api_name=f"/{api_name}") | |
loop = asyncio.get_running_loop() | |
result = await loop.run_in_executor(None, job.result) | |
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fastapi | |
uvicorn[standard] | |
gradio_client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
uvicorn main:app --reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment