umair894 commited on
Commit
bfd5578
·
verified ·
1 Parent(s): 8f7fabc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+
5
+ app = FastAPI(title="Minimal FastAPI on HF Spaces")
6
+
7
+ class Item(BaseModel):
8
+ text: str
9
+
10
+ @app.get("/")
11
+ def read_root():
12
+ return {"hello": "world"}
13
+
14
+ @app.post("/echo")
15
+ def echo(item: Item):
16
+ return {"echo": item.text}
17
+
18
+ # Needed when running in a Python Space: bind to 0.0.0.0 and the provided PORT
19
+ if __name__ == "__main__":
20
+ import uvicorn
21
+ uvicorn.run(
22
+ app,
23
+ host="0.0.0.0",
24
+ port=int(os.environ.get("PORT", 7860)),
25
+ )