Spaces:
Runtime error
Runtime error
File size: 1,254 Bytes
df8d5b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import os
import requests
import json
from io import BytesIO
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse, StreamingResponse
from modules.inference import infer_t5
from modules.dataset import query_emotion
# https://huggingface.co./settings/tokens
# https://huggingface.co./spaces/{username}/{space}/settings
API_TOKEN = os.getenv("BIG_GAN_TOKEN")
app = FastAPI(docs_url=None, redoc_url=None)
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.head("/")
@app.get("/")
def index() -> FileResponse:
return FileResponse(path="static/index.html", media_type="text/html")
@app.get("/infer_biggan")
def biggan(input):
output = requests.request(
"POST",
"https://api-inference.huggingface.co/models/osanseviero/BigGAN-deep-128",
headers={"Authorization": f"Bearer {API_TOKEN}"},
data=json.dumps(input),
)
return StreamingResponse(BytesIO(output.content), media_type="image/png")
@app.get("/infer_t5")
def t5(input):
output = infer_t5(input)
return {"output": output}
@app.get("/query_emotion")
def emotion(start, end):
output = query_emotion(int(start), int(end))
return {"output": output}
|