Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.staticfiles import StaticFiles
|
| 3 |
+
from fastapi.responses import HTMLResponse
|
| 4 |
+
from py_mini_racer import py_mini_racer
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 8 |
+
|
| 9 |
+
@app.get("/")
|
| 10 |
+
async def index():
|
| 11 |
+
# Create an instance of PyMiniRacer
|
| 12 |
+
ctx = py_mini_racer.MiniRacer()
|
| 13 |
+
|
| 14 |
+
# Read the JavaScript code
|
| 15 |
+
with open("static/script.js", "r") as file:
|
| 16 |
+
javascript_code = file.read()
|
| 17 |
+
|
| 18 |
+
# Execute the JavaScript code
|
| 19 |
+
ctx.execute(javascript_code)
|
| 20 |
+
|
| 21 |
+
# Get the result of the JavaScript execution
|
| 22 |
+
result = ctx.eval("window.voiceflow.chat.load({ verify: { projectID: '656181267913810007e3e0b5' }, url: 'https://general-runtime.voiceflow.com', versionID: 'production' });")
|
| 23 |
+
|
| 24 |
+
# Return the result as HTML response
|
| 25 |
+
return HTMLResponse(content=result, status_code=200)
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
import uvicorn
|
| 29 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|