Spaces:
Runtime error
Runtime error
Commit
·
d760545
1
Parent(s):
39c1111
uP
Browse files
app.py
CHANGED
@@ -1,11 +1,20 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
4 |
import re
|
5 |
|
6 |
from fastapi import FastAPI
|
7 |
from fastapi import Request
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
@@ -29,3 +38,22 @@ async def webhook(request: Request):
|
|
29 |
content = payload["comment"]["content"]
|
30 |
title = payload["discussion"]["title"]
|
31 |
image_urls = url_re.findall(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import HfApi
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
import huggingface_hub
|
4 |
+
from huggingface_hub import get_repo_discussions
|
5 |
+
from bs4 import BeautifulSoup
|
6 |
+
import json
|
7 |
import re
|
8 |
|
9 |
from fastapi import FastAPI
|
10 |
from fastapi import Request
|
11 |
|
12 |
+
repo_id = "dalle-mini/dalle-mini"
|
13 |
+
repo_id = "stabilityai/stable-diffusion"
|
14 |
+
dataset_repo_id = "triple-t/dummy"
|
15 |
+
path = "image_cache"
|
16 |
+
file_name = "_".join(repo_id.split("/")) + ".json"
|
17 |
+
api = HfApi()
|
18 |
|
19 |
app = FastAPI()
|
20 |
|
|
|
38 |
content = payload["comment"]["content"]
|
39 |
title = payload["discussion"]["title"]
|
40 |
image_urls = url_re.findall(content)
|
41 |
+
|
42 |
+
data_dict = {"data": {"images": image_urls, "prompt": title}, "discussion_num": 1000}
|
43 |
+
|
44 |
+
path = hf_hub_download(repo_id=dataset_repo_id, filename=file_name, cache_dir=path, repo_type="dataset")
|
45 |
+
|
46 |
+
with open(path, "r") as f:
|
47 |
+
data = json.load(f)
|
48 |
+
|
49 |
+
data.append(data_dict)
|
50 |
+
|
51 |
+
with open(path, "w") as f:
|
52 |
+
f.write(json.dumps(data, sort_keys=True, indent=4))
|
53 |
+
|
54 |
+
api.upload_file(
|
55 |
+
path_or_fileobj=path,
|
56 |
+
path_in_repo=file_name,
|
57 |
+
repo_id=dataset_repo_id,
|
58 |
+
repo_type="dataset",
|
59 |
+
)
|