multimodalart HF staff commited on
Commit
a541bac
1 Parent(s): bce144b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -42,7 +42,10 @@ def get_prompts_from_image(image_id):
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
 
@@ -58,7 +61,7 @@ def extract_info(json_data):
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,7 +69,8 @@ def extract_info(json_data):
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",
@@ -102,6 +106,7 @@ def download_files(info, folder="."):
102
  downloaded_files = {
103
  "imageName": [],
104
  "imagePrompt": [],
 
105
  "weightName": []
106
  }
107
  for item in info["urls_to_download"]:
@@ -109,7 +114,9 @@ def download_files(info, folder="."):
109
  downloaded_files[item["type"]].append(item["filename"])
110
  if(item["type"] == "imageName"):
111
  prompt_clean = re.sub(r'<.*?>', '', item["prompt"])
 
112
  downloaded_files["imagePrompt"].append(prompt_clean)
 
113
  return downloaded_files
114
 
115
  def download_file(url, filename, folder="."):
@@ -159,9 +166,11 @@ You should use {formatted_words} to trigger the image generation.
159
  trigger_words_section = ""
160
 
161
  widget_content = ""
162
- for index, (prompt, image) in enumerate(zip(downloaded_files["imagePrompt"], downloaded_files["imageName"])):
163
  escaped_prompt = prompt.replace("'", "''")
164
  widget_content += f"""- text: '{escaped_prompt if escaped_prompt else ' ' }'
 
 
165
  output:
166
  url: >-
167
  {image}
 
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
+ if(len(content) > 1):
46
+ return content[0].text, content[1].text
47
+ else:
48
+ return content[0].text, ""
49
  else:
50
  return ""
51
 
 
61
  # Then append all image URLs to the list
62
  for image in model_version["images"]:
63
  image_id = image["url"].split("/")[-1]
64
+ prompt, negative_prompt = get_prompts_from_image(image_id)
65
  if image["nsfwLevel"] > 2:
66
  pass #ugly before checking the actual logic
67
  else:
 
69
  "url": image["url"],
70
  "filename": os.path.basename(image["url"]),
71
  "type": "imageName",
72
+ "prompt": prompt, #if "meta" in image and "prompt" in image["meta"] else ""
73
+ "negative_prompt": negative_prompt
74
  })
75
  model_mapping = {
76
  "SDXL 1.0": "stabilityai/stable-diffusion-xl-base-1.0",
 
106
  downloaded_files = {
107
  "imageName": [],
108
  "imagePrompt": [],
109
+ "imageNegativePrompt": [],
110
  "weightName": []
111
  }
112
  for item in info["urls_to_download"]:
 
114
  downloaded_files[item["type"]].append(item["filename"])
115
  if(item["type"] == "imageName"):
116
  prompt_clean = re.sub(r'<.*?>', '', item["prompt"])
117
+ negative_prompt_clean = re.sub(r'<.*?>', '', item["negative_prompt"])
118
  downloaded_files["imagePrompt"].append(prompt_clean)
119
+ downloaded_files["imageNegativePrompt"].append(negative_prompt_clean)
120
  return downloaded_files
121
 
122
  def download_file(url, filename, folder="."):
 
166
  trigger_words_section = ""
167
 
168
  widget_content = ""
169
+ for index, (prompt, negative_prompt, image) in enumerate(zip(downloaded_files["imagePrompt"], downloaded_files["imageNegativePrompt"], downloaded_files["imageName"])):
170
  escaped_prompt = prompt.replace("'", "''")
171
  widget_content += f"""- text: '{escaped_prompt if escaped_prompt else ' ' }'
172
+ parameters:
173
+ negative_prompt: {negative_prompt}
174
  output:
175
  url: >-
176
  {image}