Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
tags data
Browse files- app.py +20 -4
- requirements.txt +2 -1
app.py
CHANGED
@@ -8,6 +8,7 @@ import subprocess
|
|
8 |
import asyncio
|
9 |
from io import BytesIO
|
10 |
import uuid
|
|
|
11 |
|
12 |
from math import ceil
|
13 |
from tqdm import tqdm
|
@@ -53,6 +54,9 @@ repo.git_pull()
|
|
53 |
|
54 |
database = Database(DB_FOLDER)
|
55 |
|
|
|
|
|
|
|
56 |
|
57 |
async def upload_resize_image_url(session, image_url):
|
58 |
print(f"Uploading image {image_url}")
|
@@ -92,6 +96,16 @@ def fetch_model_card(model_id):
|
|
92 |
return response.text
|
93 |
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
async def find_image_in_model_card(text):
|
96 |
image_regex = re.compile(r'https?://\S+(?:png|jpg|jpeg|webp)')
|
97 |
urls = re.findall(image_regex, text)
|
@@ -207,11 +221,13 @@ async def sync_data():
|
|
207 |
for model in tqdm(models_no_images):
|
208 |
model_id = model['id']
|
209 |
model_data = json.loads(model['data'])
|
210 |
-
print("Updating model", model_id)
|
211 |
model_card = fetch_model_card(model_id)
|
|
|
212 |
images = await find_image_in_model_card(model_card)
|
213 |
classifier = run_classifier(images)
|
214 |
-
|
|
|
|
|
215 |
# update model row with image and classifier data
|
216 |
with database.get_db() as db:
|
217 |
cursor = db.cursor()
|
@@ -234,7 +250,7 @@ async def sync_data():
|
|
234 |
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
235 |
cmd = f"git add . && git commit --amend -m 'update at {time}' && git push --force"
|
236 |
print(cmd)
|
237 |
-
subprocess.Popen(cmd, cwd=DB_FOLDER, shell=True)
|
238 |
|
239 |
|
240 |
app = FastAPI()
|
@@ -327,7 +343,7 @@ def read_root():
|
|
327 |
# return html page from string
|
328 |
return HTMLResponse("""
|
329 |
<p>Just a bot to sync data from diffusers gallery please go to
|
330 |
-
<a href="https://huggingface.co/spaces/huggingface-projects/diffusers-gallery">https://huggingface.co/spaces/huggingface-projects/diffusers-gallery</a>
|
331 |
</p>""")
|
332 |
|
333 |
|
|
|
8 |
import asyncio
|
9 |
from io import BytesIO
|
10 |
import uuid
|
11 |
+
import yaml
|
12 |
|
13 |
from math import ceil
|
14 |
from tqdm import tqdm
|
|
|
54 |
|
55 |
database = Database(DB_FOLDER)
|
56 |
|
57 |
+
REGEX_YAML_BLOCK = re.compile(
|
58 |
+
r"^(\s*---[\r\n]+)([\S\s]*?)([\r\n]+---(\r\n|\n|$))")
|
59 |
+
|
60 |
|
61 |
async def upload_resize_image_url(session, image_url):
|
62 |
print(f"Uploading image {image_url}")
|
|
|
96 |
return response.text
|
97 |
|
98 |
|
99 |
+
def get_yaml_data(text_content):
|
100 |
+
match = REGEX_YAML_BLOCK.search(text_content)
|
101 |
+
if match:
|
102 |
+
yaml_block = match.group(2)
|
103 |
+
data_dict = yaml.safe_load(yaml_block)
|
104 |
+
else:
|
105 |
+
data_dict = {}
|
106 |
+
return data_dict
|
107 |
+
|
108 |
+
|
109 |
async def find_image_in_model_card(text):
|
110 |
image_regex = re.compile(r'https?://\S+(?:png|jpg|jpeg|webp)')
|
111 |
urls = re.findall(image_regex, text)
|
|
|
221 |
for model in tqdm(models_no_images):
|
222 |
model_id = model['id']
|
223 |
model_data = json.loads(model['data'])
|
|
|
224 |
model_card = fetch_model_card(model_id)
|
225 |
+
model_card_data = get_yaml_data(model_card)
|
226 |
images = await find_image_in_model_card(model_card)
|
227 |
classifier = run_classifier(images)
|
228 |
+
model_data['images'] = images
|
229 |
+
model_data['class'] = classifier
|
230 |
+
model_data['meta'] = model_card_data
|
231 |
# update model row with image and classifier data
|
232 |
with database.get_db() as db:
|
233 |
cursor = db.cursor()
|
|
|
250 |
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
251 |
cmd = f"git add . && git commit --amend -m 'update at {time}' && git push --force"
|
252 |
print(cmd)
|
253 |
+
# subprocess.Popen(cmd, cwd=DB_FOLDER, shell=True)
|
254 |
|
255 |
|
256 |
app = FastAPI()
|
|
|
343 |
# return html page from string
|
344 |
return HTMLResponse("""
|
345 |
<p>Just a bot to sync data from diffusers gallery please go to
|
346 |
+
<a href="https://huggingface.co/spaces/huggingface-projects/diffusers-gallery" target="_blank" rel="noopener noreferrer">https://huggingface.co/spaces/huggingface-projects/diffusers-gallery</a>
|
347 |
</p>""")
|
348 |
|
349 |
|
requirements.txt
CHANGED
@@ -7,4 +7,5 @@ requests
|
|
7 |
asyncio
|
8 |
aiohttp
|
9 |
Pillow
|
10 |
-
boto3
|
|
|
|
7 |
asyncio
|
8 |
aiohttp
|
9 |
Pillow
|
10 |
+
boto3
|
11 |
+
yaml
|