GalaxyTab commited on
Commit
6fe667b
·
1 Parent(s): cd11223

added app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -78
app.py CHANGED
@@ -1,84 +1,7 @@
1
- from fastapi import FastAPI, Body
2
- from pydantic import BaseModel
3
- from typing import List, Optional
4
-
5
- import time
6
-
7
  import json
8
- import os
9
- import pandas as pd
10
- import getNewSec
11
-
12
- from tokenizeAPIHelpers import datasetHandler, tokenizeDir
13
- from hf_login import hf_login
14
-
15
- from huggingface_hub import HfApi, SpaceHardware
16
 
17
  app = FastAPI()
18
-
19
- class TickerItem(BaseModel):
20
- ticker: str
21
- cik: str
22
- lastSync: Optional[str] = None
23
-
24
- @app.post("/downgradeTS")
25
- def downgradeTS():
26
- token = os.getenv("HF_TOKEN")
27
- if not token:
28
- raise RuntimeError("HF_TOKEN not found in environment or .env file")
29
-
30
- api = HfApi(token=token)
31
- repo = "UMWRoom225/tokenizer"
32
- api.request_space_hardware(repo_id=repo, hardware=SpaceHardware.CPU_BASIC)
33
- return {"ok": True, "hardware": "CPU_BASIC"}
34
-
35
- @app.post("/upgradeTS")
36
- def upgradeTS():
37
- token = os.getenv("HF_TOKEN")
38
- if not token:
39
- raise RuntimeError("HF_TOKEN not found in environment or .env file")
40
-
41
- api = HfApi(token=token)
42
- repo = "UMWRoom225/tokenizer"
43
- api.request_space_hardware(repo_id=repo, hardware=SpaceHardware.CPU_UPGRADE)
44
- return {"ok": True, "hardware": "CPU_UPGRADE"}
45
-
46
  @app.get("/")
47
  def statusCheck():
48
  return {"status": "running"}
49
-
50
- @app.get("/health")
51
- def health():
52
- token = os.getenv("HF_TOKEN")
53
- if not token:
54
- raise RuntimeError("HF_TOKEN not found in environment or .env file")
55
-
56
- api = HfApi(token=token)
57
- repo = "UMWRoom225/tokenizer"
58
-
59
- state=api.get_space_runtime(repo_id=repo)
60
- if(state.stage == "RUNNING"):
61
- return {"ok": True}
62
- else:
63
- return {"ok":False}
64
-
65
-
66
- @app.post("/tokenize")
67
- def writeNewDocs(items: List[TickerItem] = Body(...)):
68
- hf_login()
69
- print("LETSSS GET TS",flush=True)
70
- ticksDf = pd.DataFrame([i.model_dump() for i in items])
71
- ticksDf = ticksDf.iloc[0:2]
72
- print(ticksDf,flush=True)
73
- toUpdate = getNewSec.main(ticksDf)
74
- print(toUpdate,flush=True)
75
- rtn = list(toUpdate)
76
-
77
- print(rtn,flush=True)
78
- time.sleep(10)
79
- tokenizeDir(".", "tmp/", max_docs=300)
80
- print("past tokenize",flush=True)
81
- time.sleep(10)
82
-
83
- return (rtn)
84
-
 
1
+ from fastapi import FastAPI
 
 
 
 
 
2
  import json
 
 
 
 
 
 
 
 
3
 
4
  app = FastAPI()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.get("/")
6
  def statusCheck():
7
  return {"status": "running"}