Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,19 +36,37 @@ def check_nsfw(json_data, profile):
|
|
| 36 |
return True
|
| 37 |
|
| 38 |
def get_prompts_from_image(image_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
url = f'https://civitai.com/images/{image_id}'
|
| 40 |
response = requests.get(url)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
if
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
def extract_info(json_data):
|
| 54 |
if json_data["type"] == "LORA":
|
|
|
|
| 36 |
return True
|
| 37 |
|
| 38 |
def get_prompts_from_image(image_id):
|
| 39 |
+
headers = {
|
| 40 |
+
"authority": "civitai.com",
|
| 41 |
+
"accept": "*/*",
|
| 42 |
+
"accept-language": "en-BR,en;q=0.9,pt-BR;q=0.8,pt;q=0.7,es-ES;q=0.6,es;q=0.5,de-LI;q=0.4,de;q=0.3,en-GB;q=0.2,en-US;q=0.1,sk;q=0.1",
|
| 43 |
+
"content-type": "application/json",
|
| 44 |
+
"cookie": f'{os.environ["COOKIE_INFO"]}',
|
| 45 |
+
"if-modified-since": "Tue, 22 Aug 2023 07:18:52 GMT",
|
| 46 |
+
"referer": f"https://civitai.com/user/{username}/models",
|
| 47 |
+
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
|
| 48 |
+
"sec-ch-ua-mobile": "?0",
|
| 49 |
+
"sec-ch-ua-platform": "macOS",
|
| 50 |
+
"sec-fetch-dest": "empty",
|
| 51 |
+
"sec-fetch-mode": "cors",
|
| 52 |
+
"sec-fetch-site": "same-origin",
|
| 53 |
+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
|
| 54 |
+
}
|
| 55 |
+
url = f'https://civitai.com/api/trpc/image.getGenerationData?input={{"json":{{"id":{image_id}}}}}'
|
| 56 |
+
response = requests.get(url, headers=headers)
|
| 57 |
url = f'https://civitai.com/images/{image_id}'
|
| 58 |
response = requests.get(url)
|
| 59 |
+
prompt = ""
|
| 60 |
+
negative_prompt = ""
|
| 61 |
+
if response.status_code == 200:
|
| 62 |
+
data = response.json()
|
| 63 |
+
result = data['result']['data']['json']
|
| 64 |
+
if "prompt" in result['meta']:
|
| 65 |
+
prompt = result['meta']['prompt']
|
| 66 |
+
if "negativePrompt" in result['meta']:
|
| 67 |
+
negative_prompt = result["meta"]["negativePrompt"]
|
| 68 |
+
|
| 69 |
+
return prompt, negative_prompt
|
| 70 |
|
| 71 |
def extract_info(json_data):
|
| 72 |
if json_data["type"] == "LORA":
|