abhijitkumarjha88192 commited on
Commit
6020013
1 Parent(s): 662a446
Files changed (4) hide show
  1. MyDataList.py +6 -0
  2. config.py +1 -0
  3. main.py +47 -4
  4. myschemas.py +19 -0
MyDataList.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+
2
+ myDataList = [
3
+ {"text": "Row 1", "description": "Description 1", "id": 1},
4
+ {"text": "Row 2", "description": "Description 2", "id": 2},
5
+ {"text": "Row 3", "description": "Description 3", "id": 3},
6
+ ]
config.py ADDED
@@ -0,0 +1 @@
 
 
1
+ cur_base_path = "/"
main.py CHANGED
@@ -1,8 +1,42 @@
1
  from typing import Optional
2
  from fastapi import FastAPI, APIRouter, Query
3
- from testpkg.finit import api_router, app
4
- from testpkg.schemas import MyDataModel, MyDataSearchResults, CreateMyDataModelEntity
5
- from testpkg.MyDataList import myDataList
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  @api_router.get("/datas/getall", status_code=200)
@@ -73,4 +107,13 @@ def delete_data(*, data_id: int) -> dict:
73
  if result:
74
  myDataList.remove(result[0])
75
 
76
- return {"datas":myDataList}
 
 
 
 
 
 
 
 
 
 
1
  from typing import Optional
2
  from fastapi import FastAPI, APIRouter, Query
3
+ #from .finit import api_router, app
4
+ from myschemas import MyDataModel, MyDataSearchResults, CreateMyDataModelEntity
5
+ from MyDataList import myDataList
6
+
7
+
8
+ app = FastAPI(title="General Purpose API", openapi_url="/openapi.json")
9
+
10
+ api_router = APIRouter()
11
+
12
+ from fastapi.middleware.cors import CORSMiddleware
13
+
14
+ # "http://localhost.tiangolo.com",
15
+ # "https://localhost.tiangolo.com",
16
+ # "http://localhost",
17
+ # "http://localhost:8080",
18
+
19
+ origins = [
20
+ "https://huggingface.co",
21
+ "https://huggingface.co/spaces/abhijitkumarjha88192/test-space",
22
+ "*"
23
+ ]
24
+
25
+ app.add_middleware(
26
+ CORSMiddleware,
27
+ allow_origins=origins,
28
+ allow_credentials=True,
29
+ allow_methods=["*"],
30
+ allow_headers=["*"],
31
+ )
32
+
33
+
34
+ @api_router.get("/", status_code=200)
35
+ def root() -> dict:
36
+ """
37
+ Root GET
38
+ """
39
+ return {"msg": "Hello, World!"}
40
 
41
 
42
  @api_router.get("/datas/getall", status_code=200)
 
107
  if result:
108
  myDataList.remove(result[0])
109
 
110
+ return {"datas":myDataList}
111
+
112
+
113
+ # if __name__ == "__main__":
114
+ # # Use this for debugging purposes only
115
+ # import uvicorn
116
+
117
+ # app.include_router(api_router)
118
+
119
+ # uvicorn.run(app, host="0.0.0.0", port=7860, log_level="debug")
myschemas.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel, HttpUrl
2
+
3
+ from typing import Sequence
4
+
5
+
6
+ class MyDataModel(BaseModel):
7
+ id: int
8
+ text: str
9
+ description: str
10
+
11
+
12
+ class MyDataSearchResults(BaseModel):
13
+ results: Sequence[MyDataModel]
14
+
15
+
16
+ class CreateMyDataModelEntity(BaseModel):
17
+ id: int
18
+ text: str
19
+ description: str