Spaces:
Running
Running
Commit
•
c5b9a3f
1
Parent(s):
7e86ef0
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import re
|
|
8 |
import uuid
|
9 |
from typing import Optional
|
10 |
import json
|
|
|
11 |
|
12 |
TRUSTED_UPLOADERS = ["KappaNeuro", "CiroN2022", "multimodalart", "Norod78", "joachimsallstrom", "blink7630", "e-n-v-y", "DoctorDiffusion", "RalFinger"]
|
13 |
|
@@ -35,6 +36,16 @@ def check_nsfw(json_data, profile):
|
|
35 |
return False
|
36 |
return True
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
def extract_info(json_data):
|
39 |
if json_data["type"] == "LORA":
|
40 |
for model_version in json_data["modelVersions"]:
|
@@ -46,7 +57,8 @@ def extract_info(json_data):
|
|
46 |
|
47 |
# Then append all image URLs to the list
|
48 |
for image in model_version["images"]:
|
49 |
-
|
|
|
50 |
if image["nsfwLevel"] > 2:
|
51 |
pass #ugly before checking the actual logic
|
52 |
else:
|
@@ -54,7 +66,7 @@ def extract_info(json_data):
|
|
54 |
"url": image["url"],
|
55 |
"filename": os.path.basename(image["url"]),
|
56 |
"type": "imageName",
|
57 |
-
"prompt":
|
58 |
})
|
59 |
model_mapping = {
|
60 |
"SDXL 1.0": "stabilityai/stable-diffusion-xl-base-1.0",
|
|
|
8 |
import uuid
|
9 |
from typing import Optional
|
10 |
import json
|
11 |
+
from bs4 import BeautifulSoup
|
12 |
|
13 |
TRUSTED_UPLOADERS = ["KappaNeuro", "CiroN2022", "multimodalart", "Norod78", "joachimsallstrom", "blink7630", "e-n-v-y", "DoctorDiffusion", "RalFinger"]
|
14 |
|
|
|
36 |
return False
|
37 |
return True
|
38 |
|
39 |
+
def get_prompts_from_image(image_id):
|
40 |
+
url = 'https://civitai.com/images/9476412'
|
41 |
+
response = requests.get(url)
|
42 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
43 |
+
content = soup.find_all(class_='mantine-Code-root mantine-Code-block mantine-2v44jn')
|
44 |
+
if(content):
|
45 |
+
return content[0].text
|
46 |
+
else:
|
47 |
+
return ""
|
48 |
+
|
49 |
def extract_info(json_data):
|
50 |
if json_data["type"] == "LORA":
|
51 |
for model_version in json_data["modelVersions"]:
|
|
|
57 |
|
58 |
# Then append all image URLs to the list
|
59 |
for image in model_version["images"]:
|
60 |
+
image_id = image["url"].split("/")[-1]
|
61 |
+
prompt = get_prompts_from_image(image_id)
|
62 |
if image["nsfwLevel"] > 2:
|
63 |
pass #ugly before checking the actual logic
|
64 |
else:
|
|
|
66 |
"url": image["url"],
|
67 |
"filename": os.path.basename(image["url"]),
|
68 |
"type": "imageName",
|
69 |
+
"prompt": prompt #if "meta" in image and "prompt" in image["meta"] else ""
|
70 |
})
|
71 |
model_mapping = {
|
72 |
"SDXL 1.0": "stabilityai/stable-diffusion-xl-base-1.0",
|