Spaces:
Runtime error
Runtime error
David Li commited on
Commit ·
ca73f58
1
Parent(s): bc77a25
Rename app.py to main.py and improve deployment workflow.
Browse files- .github/workflows/deploy.yml +4 -0
- Dockerfile +14 -0
- ReadMe.md +11 -0
- main.py → app.py +0 -0
- diff.txt +92 -0
.github/workflows/deploy.yml
CHANGED
|
@@ -5,6 +5,10 @@ jobs:
|
|
| 5 |
deploy:
|
| 6 |
runs-on: ubuntu-latest
|
| 7 |
steps:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
- uses: actions/checkout@v2 #Be sure you check-out the repo first. Deta CLI needs access to the files
|
| 9 |
- uses: BogDAAAMN/deta-deploy-action@v1.0.1
|
| 10 |
with:
|
|
|
|
| 5 |
deploy:
|
| 6 |
runs-on: ubuntu-latest
|
| 7 |
steps:
|
| 8 |
+
- run:
|
| 9 |
+
name: "mv file"
|
| 10 |
+
command: |
|
| 11 |
+
mv app.py main.py
|
| 12 |
- uses: actions/checkout@v2 #Be sure you check-out the repo first. Deta CLI needs access to the files
|
| 13 |
- uses: BogDAAAMN/deta-deploy-action@v1.0.1
|
| 14 |
with:
|
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.9
|
| 5 |
+
|
| 6 |
+
WORKDIR /code
|
| 7 |
+
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
ReadMe.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# fast-rapidapi
|
| 2 |
Simple fastapi hosted on deta for rapidapi
|
| 3 |
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Hs Fast Api
|
| 3 |
+
emoji: 🐢
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: openrail
|
| 9 |
+
port: 8000
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
# fast-rapidapi
|
| 13 |
Simple fastapi hosted on deta for rapidapi
|
| 14 |
|
main.py → app.py
RENAMED
|
File without changes
|
diff.txt
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
|
| 2 |
+
index 0aa8d59..083dc56 100644
|
| 3 |
+
--- a/.github/workflows/deploy.yml
|
| 4 |
+
+++ b/.github/workflows/deploy.yml
|
| 5 |
+
@@ -5,6 +5,10 @@ jobs:
|
| 6 |
+
deploy:
|
| 7 |
+
runs-on: ubuntu-latest
|
| 8 |
+
steps:
|
| 9 |
+
+ - run:
|
| 10 |
+
+ name: "mv file"
|
| 11 |
+
+ command: |
|
| 12 |
+
+ mv app.py main.py
|
| 13 |
+
- uses: actions/checkout@v2 #Be sure you check-out the repo first. Deta CLI needs access to the files
|
| 14 |
+
- uses: BogDAAAMN/deta-deploy-action@v1.0.1
|
| 15 |
+
with:
|
| 16 |
+
diff --git a/ReadMe.md b/ReadMe.md
|
| 17 |
+
index a791671..8ec842b 100644
|
| 18 |
+
--- a/ReadMe.md
|
| 19 |
+
+++ b/ReadMe.md
|
| 20 |
+
@@ -1,3 +1,14 @@
|
| 21 |
+
+---
|
| 22 |
+
+title: Hs Fast Api
|
| 23 |
+
+emoji: 🐢
|
| 24 |
+
+colorFrom: red
|
| 25 |
+
+colorTo: blue
|
| 26 |
+
+sdk: docker
|
| 27 |
+
+pinned: false
|
| 28 |
+
+license: openrail
|
| 29 |
+
+port: 8000
|
| 30 |
+
+---
|
| 31 |
+
+
|
| 32 |
+
# fast-rapidapi
|
| 33 |
+
Simple fastapi hosted on deta for rapidapi
|
| 34 |
+
|
| 35 |
+
diff --git a/main.py b/main.py
|
| 36 |
+
deleted file mode 100644
|
| 37 |
+
index f496628..0000000
|
| 38 |
+
--- a/main.py
|
| 39 |
+
+++ /dev/null
|
| 40 |
+
@@ -1,52 +0,0 @@
|
| 41 |
+
-from fastapi import FastAPI
|
| 42 |
+
-import pandas as pd
|
| 43 |
+
-import os
|
| 44 |
+
-from deta import Deta
|
| 45 |
+
-from fastapi.responses import StreamingResponse, FileResponse
|
| 46 |
+
-from io import BytesIO
|
| 47 |
+
-
|
| 48 |
+
-from fastapi.middleware.cors import CORSMiddleware
|
| 49 |
+
-
|
| 50 |
+
-app = FastAPI()
|
| 51 |
+
-
|
| 52 |
+
-# load deta using
|
| 53 |
+
-project_key = os.getenv("DETA_DRIVE_KEY")
|
| 54 |
+
-deta = Deta(project_key)
|
| 55 |
+
-drive = deta.Drive("stonk_events")
|
| 56 |
+
-
|
| 57 |
+
-app.add_middleware(
|
| 58 |
+
- CORSMiddleware,
|
| 59 |
+
- allow_origins=["*"],
|
| 60 |
+
- allow_credentials=True,
|
| 61 |
+
- allow_methods=["*"],
|
| 62 |
+
- allow_headers=["*"],
|
| 63 |
+
-)
|
| 64 |
+
-
|
| 65 |
+
-@app.get("/files")
|
| 66 |
+
-async def get_files(exchange: str = "US"):
|
| 67 |
+
- """
|
| 68 |
+
- """
|
| 69 |
+
- # get files in deta
|
| 70 |
+
- result = drive.list()
|
| 71 |
+
- all_files = result.get("names")
|
| 72 |
+
- paging = result.get("paging")
|
| 73 |
+
- last = paging.get("last") if paging else None
|
| 74 |
+
-
|
| 75 |
+
- while (last):
|
| 76 |
+
- # provide last from previous call
|
| 77 |
+
- result = drive.list(last=last)
|
| 78 |
+
-
|
| 79 |
+
- all_files += result.get("names")
|
| 80 |
+
- # update last
|
| 81 |
+
- paging = result.get("paging")
|
| 82 |
+
- last = paging.get("last") if paging else None
|
| 83 |
+
- return all_files
|
| 84 |
+
-
|
| 85 |
+
-
|
| 86 |
+
-# get file by name from deta /file/{id}
|
| 87 |
+
-# reason it was likely failing is because of the response size limit
|
| 88 |
+
-@app.get("/file/{id}")
|
| 89 |
+
-async def get_file(id: str):
|
| 90 |
+
- res = drive.get(id)
|
| 91 |
+
- return StreamingResponse(res.iter_chunks(1024), media_type="application/pdf")
|
| 92 |
+
-
|