radames commited on
Commit
9a6a181
1 Parent(s): 9a5a85e

change order

Browse files
Files changed (1) hide show
  1. app.py +29 -7
app.py CHANGED
@@ -1,19 +1,21 @@
1
- from enum import Enum
2
  import os
3
- import re
4
- from io import BytesIO
5
- import uuid
6
  import gradio as gr
7
  from pathlib import Path
8
  from huggingface_hub import Repository
9
  import json
10
  from db import Database
 
 
 
11
 
12
  HF_TOKEN = os.environ.get("HF_TOKEN")
13
  S3_DATA_FOLDER = Path("sd-multiplayer-data")
14
  DB_FOLDER = Path("diffusers-gallery-data")
 
15
  ASSETS_URL = "https://d26smi9133w0oo.cloudfront.net/diffusers-gallery/"
16
 
 
17
  repo = Repository(
18
  local_dir=DB_FOLDER,
19
  repo_type="dataset",
@@ -25,8 +27,6 @@ repo.git_pull()
25
  database = Database(DB_FOLDER)
26
 
27
 
28
- blocks = gr.Blocks()
29
-
30
  styles_cls = ["anime", "3D", "realistic", "other"]
31
  nsfw_cls = ["safe", "suggestive", "explicit"]
32
 
@@ -90,6 +90,7 @@ def flag_model(current_model, styles=None, nsfw=None):
90
  return next_model({}, styles, nsfw)
91
 
92
 
 
93
  with blocks:
94
  gr.Markdown('''### Diffusers Gallery annotation tool
95
  Please select multiple classes for each image. If you are unsure, select "other" and also check the model card for more information.
@@ -115,4 +116,25 @@ with blocks:
115
  blocks.load(next_model, inputs=[query_params, styles, nsfw],
116
  outputs=[gallery, model_title, styles, nsfw, current_model], _js=js_get_url_params)
117
 
118
- blocks.launch(enable_queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import uvicorn
 
 
3
  import gradio as gr
4
  from pathlib import Path
5
  from huggingface_hub import Repository
6
  import json
7
  from db import Database
8
+ from fastapi import FastAPI
9
+ from datetime import datetime
10
+ import subprocess
11
 
12
  HF_TOKEN = os.environ.get("HF_TOKEN")
13
  S3_DATA_FOLDER = Path("sd-multiplayer-data")
14
  DB_FOLDER = Path("diffusers-gallery-data")
15
+
16
  ASSETS_URL = "https://d26smi9133w0oo.cloudfront.net/diffusers-gallery/"
17
 
18
+
19
  repo = Repository(
20
  local_dir=DB_FOLDER,
21
  repo_type="dataset",
 
27
  database = Database(DB_FOLDER)
28
 
29
 
 
 
30
  styles_cls = ["anime", "3D", "realistic", "other"]
31
  nsfw_cls = ["safe", "suggestive", "explicit"]
32
 
 
90
  return next_model({}, styles, nsfw)
91
 
92
 
93
+ blocks = gr.Blocks()
94
  with blocks:
95
  gr.Markdown('''### Diffusers Gallery annotation tool
96
  Please select multiple classes for each image. If you are unsure, select "other" and also check the model card for more information.
 
116
  blocks.load(next_model, inputs=[query_params, styles, nsfw],
117
  outputs=[gallery, model_title, styles, nsfw, current_model], _js=js_get_url_params)
118
 
119
+
120
+ app = FastAPI()
121
+
122
+
123
+ @app.get("/sync")
124
+ def read_main():
125
+ sync_data()
126
+ return "Synced flagged"
127
+
128
+
129
+ def sync_data():
130
+ print("Updating DB repository")
131
+ time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
132
+ subprocess.Popen(
133
+ f"git add . && git commit --amend -m 'update at flags {time}' && git push --force", cwd=DB_FOLDER, shell=True)
134
+
135
+
136
+ app = gr.mount_gradio_app(app, blocks, "/")
137
+
138
+
139
+ if __name__ == "__main__":
140
+ uvicorn.run(app, host='0.0.0.0', port=7860)