Upload folder using huggingface_hub
Browse files- .gitignore +1 -0
- Dockerfile +13 -0
- app.py +43 -0
- filesystem.py +19 -0
- requirements.txt +3 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.db
|
Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
RUN useradd -m -u 1000 user
|
| 4 |
+
USER user
|
| 5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY --chown=user . /app
|
| 13 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import sqlite3
|
| 4 |
+
import threading
|
| 5 |
+
from pydantic import BaseModel
|
| 6 |
+
from fastapi import FastAPI
|
| 7 |
+
from huggingface_hub import HfApi
|
| 8 |
+
from filesystem import upload, download
|
| 9 |
+
|
| 10 |
+
app = FastAPI()
|
| 11 |
+
|
| 12 |
+
class sql(BaseModel):
|
| 13 |
+
sql: str
|
| 14 |
+
|
| 15 |
+
download()
|
| 16 |
+
|
| 17 |
+
def Upload():
|
| 18 |
+
while True:
|
| 19 |
+
upload()
|
| 20 |
+
time.sleep(30)
|
| 21 |
+
|
| 22 |
+
def Connect():
|
| 23 |
+
conn = sqlite3.connect("database.db")
|
| 24 |
+
cursor = conn.cursor()
|
| 25 |
+
return conn, cursor
|
| 26 |
+
|
| 27 |
+
thread = threading.Thread(target=Upload)
|
| 28 |
+
thread.start()
|
| 29 |
+
|
| 30 |
+
@app.get("/")
|
| 31 |
+
def HuggingFaceSpaceRoot():
|
| 32 |
+
return ""
|
| 33 |
+
|
| 34 |
+
@app.head("/")
|
| 35 |
+
def UptimeRobot():
|
| 36 |
+
return "OK"
|
| 37 |
+
|
| 38 |
+
@app.post("/sql")
|
| 39 |
+
def execute_sql(param: sql):
|
| 40 |
+
conn, cursor = Connect()
|
| 41 |
+
cursor.execute(param.sql)
|
| 42 |
+
conn.commit()
|
| 43 |
+
conn.close()
|
filesystem.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import HfApi
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
api = HfApi(token=os.getenv("HF_TOKEN"))
|
| 5 |
+
|
| 6 |
+
def download():
|
| 7 |
+
api.hf_hub_download(
|
| 8 |
+
repo_type="dataset",
|
| 9 |
+
repo_id="xcx0902/database",
|
| 10 |
+
filename="database.db"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def upload():
|
| 14 |
+
api.upload_folder(
|
| 15 |
+
folder_path=".",
|
| 16 |
+
repo_type="dataset",
|
| 17 |
+
repo_id="xcx0902/database",
|
| 18 |
+
allow_patterns="database.db"
|
| 19 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
huggingface_hub
|