Spaces:
Sleeping
Sleeping
Update modules/app.py
Browse files- modules/app.py +26 -45
modules/app.py
CHANGED
|
@@ -1,51 +1,32 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
from io import BytesIO
|
| 5 |
-
|
| 6 |
-
from fastapi import FastAPI
|
| 7 |
-
from fastapi.staticfiles import StaticFiles
|
| 8 |
-
from fastapi.responses import FileResponse, StreamingResponse
|
| 9 |
-
|
| 10 |
-
from modules.inference import infer_t5
|
| 11 |
-
from modules.dataset import query_emotion
|
| 12 |
-
|
| 13 |
-
# https://huggingface.co/settings/tokens
|
| 14 |
-
# https://huggingface.co/spaces/{username}/{space}/settings
|
| 15 |
-
API_TOKEN = os.getenv("BIG_GAN_TOKEN")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
@app.head("/")
|
| 23 |
@app.get("/")
|
| 24 |
-
def
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
return {"output": output}
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
@app.get("/query_emotion")
|
| 48 |
-
def emotion(start, end):
|
| 49 |
-
output = query_emotion(int(start), int(end))
|
| 50 |
-
|
| 51 |
-
return {"output": output}
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Query, Request
|
| 2 |
import os
|
| 3 |
+
from typing import Any, Optional, Dict
|
| 4 |
+
from person import Person
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
import requests
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
app = FastAPI(
|
| 9 |
+
title="Test"
|
| 10 |
+
)
|
| 11 |
|
| 12 |
@app.head("/")
|
| 13 |
@app.get("/")
|
| 14 |
+
async def get_user_info(request: Request) -> Dict[str, str]:
|
| 15 |
+
client_host = request.headers.get('x-forwarded-for')
|
| 16 |
+
user_agent = request.headers.get('user-agent')
|
| 17 |
+
|
| 18 |
+
print(request.headers)
|
| 19 |
+
|
| 20 |
+
return {
|
| 21 |
+
"IP Address": client_host,
|
| 22 |
+
"User Agent": user_agent,
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
def push_noti_tele(message):
|
| 26 |
+
url = f"https://api.telegram.org/bot7210957168:AAEy0umCg4VTCilHTE3yICnsQT8cPrbeOr4/sendMessage"
|
| 27 |
+
|
| 28 |
+
payload = {
|
| 29 |
+
"chat_id": "-4159820605",
|
| 30 |
+
"text": message
|
| 31 |
+
}
|
| 32 |
+
response = requests.post(url, data=payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|