Spaces:
Runtime error
Runtime error
initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastapi import FastAPI, Request, Response
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
|
| 6 |
+
@app.middleware("http")
|
| 7 |
+
async def some_fastapi_middleware(request: Request, call_next):
|
| 8 |
+
path = request.scope['path'] # get the request route
|
| 9 |
+
response = await call_next(request)
|
| 10 |
+
|
| 11 |
+
if path == "/":
|
| 12 |
+
response_body = ""
|
| 13 |
+
async for chunk in response.body_iterator:
|
| 14 |
+
response_body += chunk.decode()
|
| 15 |
+
|
| 16 |
+
some_javascript = f"""
|
| 17 |
+
<script type="text/javascript" defer>
|
| 18 |
+
console.log("middleware");
|
| 19 |
+
</script>
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
response_body = response_body.replace("</body>", some_javascript + "</body>")
|
| 23 |
+
|
| 24 |
+
del response.headers["content-length"]
|
| 25 |
+
|
| 26 |
+
return Response(
|
| 27 |
+
content=response_body,
|
| 28 |
+
status_code=response.status_code,
|
| 29 |
+
headers=dict(response.headers),
|
| 30 |
+
media_type=response.media_type
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
return response
|
| 34 |
+
|
| 35 |
+
def greet(source):
|
| 36 |
+
print("greet")
|
| 37 |
+
print(source)
|
| 38 |
+
return ("Hello ", 768, 768)
|
| 39 |
+
|
| 40 |
+
html_text = f"""
|
| 41 |
+
<canvas id="canvas" width="512" height="512"></canvas>
|
| 42 |
+
<script type="text/javascript" defer>{file_contents}</script>
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
with gr.Blocks() as demo:
|
| 46 |
+
with gr.Row():
|
| 47 |
+
with gr.Column(scale=1):
|
| 48 |
+
source = gr.Image(type="pil")
|
| 49 |
+
btn = gr.Button(value="Fetch pose")
|
| 50 |
+
width = gr.Slider(label="Width", mininmum=512, maximum=1024, step=64, value=512, key="Width", interactive=True)
|
| 51 |
+
height = gr.Slider(label="Height", mininmum=512, maximum=1024, step=64, value=512, key="Height", interactive=True)
|
| 52 |
+
with gr.Column(scale=2):
|
| 53 |
+
html = gr.HTML(html_text)
|
| 54 |
+
console = gr.Textbox(label="console")
|
| 55 |
+
|
| 56 |
+
btn.click(
|
| 57 |
+
fn = None,
|
| 58 |
+
inputs = source, outputs = [console, width, height],
|
| 59 |
+
_js="(i) => { console.log(typeof(i)); initializePose(); return [i, 1024, 1024]; }")
|
| 60 |
+
width.change(fn=None, _js="(i) => { console.log(i); resizeCanvas(i, null); return i; }")
|
| 61 |
+
height.change(fn=None, _js="(i) => { console.log(i); resizeCanvas(null, i); return i; }")
|
| 62 |
+
|
| 63 |
+
gr.mount_gradio_app(app, demo, path="/")
|
start.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
|
| 3 |
+
subprocess.run("uvicorn modules.app:app --host 0.0.0.0 --port 7860", shell=True)
|