database / app.py
xcx0902's picture
Upload folder using huggingface_hub
61a1270 verified
raw
history blame
738 Bytes
import os
import time
import sqlite3
import threading
from pydantic import BaseModel
from fastapi import FastAPI
from huggingface_hub import HfApi
from filesystem import upload, download
app = FastAPI()
class sql(BaseModel):
sql: str
download()
def Upload():
while True:
upload()
time.sleep(30)
def Connect():
conn = sqlite3.connect("database.db")
cursor = conn.cursor()
return conn, cursor
thread = threading.Thread(target=Upload)
thread.start()
@app.get("/")
def HuggingFaceSpaceRoot():
return ""
@app.head("/")
def UptimeRobot():
return "OK"
@app.post("/sql")
def execute_sql(param: sql):
conn, cursor = Connect()
cursor.execute(param.sql)
conn.commit()
conn.close()