tqhoa commited on
Commit
6ab02ca
·
verified ·
1 Parent(s): 8ac1ee6

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +26 -45
modules/app.py CHANGED
@@ -1,51 +1,32 @@
 
1
  import os
2
- import requests
3
- import json
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
- app = FastAPI(docs_url=None, redoc_url=None)
18
-
19
- app.mount("/static", StaticFiles(directory="static"), name="static")
20
 
 
 
 
21
 
22
  @app.head("/")
23
  @app.get("/")
24
- def index() -> FileResponse:
25
- return FileResponse(path="static/index.html", media_type="text/html")
26
-
27
-
28
- @app.get("/infer_biggan")
29
- def biggan(input):
30
- output = requests.request(
31
- "POST",
32
- "https://api-inference.huggingface.co/models/osanseviero/BigGAN-deep-128",
33
- headers={"Authorization": f"Bearer {API_TOKEN}"},
34
- data=json.dumps(input),
35
- )
36
-
37
- return StreamingResponse(BytesIO(output.content), media_type="image/png")
38
-
39
-
40
- @app.get("/infer_t5")
41
- def t5(input):
42
- output = infer_t5(input)
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)