Spaces:
Runtime error
Runtime error
force push overwrite
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ import shutil
|
|
| 12 |
from PIL import Image
|
| 13 |
import sqlite3
|
| 14 |
from huggingface_hub import Repository
|
|
|
|
| 15 |
|
| 16 |
app = Flask(__name__, static_url_path='/static')
|
| 17 |
|
|
@@ -71,41 +72,39 @@ def update_repository():
|
|
| 71 |
db.row_factory = sqlite3.Row
|
| 72 |
result = db.execute("SELECT * FROM prompts").fetchall()
|
| 73 |
# data = [dict(row) for row in result]
|
| 74 |
-
|
| 75 |
# with open('./data/data.json', 'w') as f:
|
| 76 |
# json.dump(data, f, separators=(',', ':'))
|
| 77 |
|
| 78 |
print("Updating repository")
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
-
@app.route('/')
|
| 83 |
def index():
|
| 84 |
return app.send_static_file('index.html')
|
| 85 |
|
| 86 |
|
| 87 |
-
@app.route('/force_push')
|
| 88 |
def push():
|
| 89 |
if(request.headers['token'] == TOKEN):
|
| 90 |
print("Force Push repository")
|
| 91 |
shutil.copyfile(DB_FILE, "./data/prompts.db")
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
os.system("git add .")
|
| 95 |
-
os.system("git commit -m 'force push'")
|
| 96 |
-
os.system("git push --force")
|
| 97 |
-
os.chdir(oldpwd)
|
| 98 |
return "Success", 200
|
| 99 |
else:
|
| 100 |
return "Error", 401
|
| 101 |
|
| 102 |
|
| 103 |
-
@app.route('/data')
|
| 104 |
def getdata():
|
| 105 |
return app.send_static_file('data.json')
|
| 106 |
|
| 107 |
|
| 108 |
-
@app.route('/prompt', methods=['POST', 'GET'])
|
| 109 |
def create():
|
| 110 |
if request.method == 'POST':
|
| 111 |
try:
|
|
@@ -129,7 +128,7 @@ if __name__ == '__main__':
|
|
| 129 |
print("Starting scheduler -- Running Production")
|
| 130 |
scheduler = APScheduler()
|
| 131 |
scheduler.add_job(id='Update Dataset Repository',
|
| 132 |
-
func=update_repository, trigger='interval', hours=
|
| 133 |
scheduler.start()
|
| 134 |
else:
|
| 135 |
print("Not Starting scheduler -- Running Development")
|
|
|
|
| 12 |
from PIL import Image
|
| 13 |
import sqlite3
|
| 14 |
from huggingface_hub import Repository
|
| 15 |
+
import subprocess
|
| 16 |
|
| 17 |
app = Flask(__name__, static_url_path='/static')
|
| 18 |
|
|
|
|
| 72 |
db.row_factory = sqlite3.Row
|
| 73 |
result = db.execute("SELECT * FROM prompts").fetchall()
|
| 74 |
# data = [dict(row) for row in result]
|
| 75 |
+
os
|
| 76 |
# with open('./data/data.json', 'w') as f:
|
| 77 |
# json.dump(data, f, separators=(',', ':'))
|
| 78 |
|
| 79 |
print("Updating repository")
|
| 80 |
+
subprocess.Popen(
|
| 81 |
+
"git add . && git commit --amend -m 'update' && git push --force", cwd="./data", shell=True)
|
| 82 |
+
# repo.push_to_hub(blocking=False)
|
| 83 |
|
| 84 |
|
| 85 |
+
@ app.route('/')
|
| 86 |
def index():
|
| 87 |
return app.send_static_file('index.html')
|
| 88 |
|
| 89 |
|
| 90 |
+
@ app.route('/force_push')
|
| 91 |
def push():
|
| 92 |
if(request.headers['token'] == TOKEN):
|
| 93 |
print("Force Push repository")
|
| 94 |
shutil.copyfile(DB_FILE, "./data/prompts.db")
|
| 95 |
+
subprocess.Popen(
|
| 96 |
+
"git add . && git commit --amend -m 'update' && git push --force", cwd="./data", shell=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
return "Success", 200
|
| 98 |
else:
|
| 99 |
return "Error", 401
|
| 100 |
|
| 101 |
|
| 102 |
+
@ app.route('/data')
|
| 103 |
def getdata():
|
| 104 |
return app.send_static_file('data.json')
|
| 105 |
|
| 106 |
|
| 107 |
+
@ app.route('/prompt', methods=['POST', 'GET'])
|
| 108 |
def create():
|
| 109 |
if request.method == 'POST':
|
| 110 |
try:
|
|
|
|
| 128 |
print("Starting scheduler -- Running Production")
|
| 129 |
scheduler = APScheduler()
|
| 130 |
scheduler.add_job(id='Update Dataset Repository',
|
| 131 |
+
func=update_repository, trigger='interval', hours=1)
|
| 132 |
scheduler.start()
|
| 133 |
else:
|
| 134 |
print("Not Starting scheduler -- Running Development")
|