Spaces:
Runtime error
Runtime error
add safety checker
Browse files
app.py
CHANGED
|
@@ -3,12 +3,26 @@ from urllib.parse import urlparse
|
|
| 3 |
import requests
|
| 4 |
import time
|
| 5 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
from utils.gradio_helpers import parse_outputs, process_outputs
|
| 8 |
|
| 9 |
names = ['prompt', 'negative_prompt', 'subject', 'number_of_outputs', 'number_of_images_per_pose', 'randomise_poses', 'output_format', 'output_quality', 'seed']
|
| 10 |
|
| 11 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 12 |
headers = {'Content-Type': 'application/json'}
|
| 13 |
|
| 14 |
payload = {"input": {}}
|
|
@@ -46,6 +60,26 @@ def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
|
| 46 |
raise gr.Error(f"Sorry, the Cog image is still processing. Try again in a bit.")
|
| 47 |
raise gr.Error(f"The submission failed! Error: {response.status_code}")
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
title = "Demo for consistent-character cog image by fofr"
|
| 50 |
description = "Create images of a given character in different poses • running cog image by fofr"
|
| 51 |
|
|
@@ -121,7 +155,7 @@ with gr.Blocks(css=css) as app:
|
|
| 121 |
outputs = [consistent_results]
|
| 122 |
|
| 123 |
submit_btn.click(
|
| 124 |
-
fn =
|
| 125 |
inputs = inputs,
|
| 126 |
outputs = outputs,
|
| 127 |
show_api = False
|
|
|
|
| 3 |
import requests
|
| 4 |
import time
|
| 5 |
import os
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 9 |
+
from gradio_client import Client
|
| 10 |
+
client = Client("fffiloni/safety-checker-bot", hf_token=hf_token)
|
| 11 |
+
|
| 12 |
+
def safety_check(user_prompt):
|
| 13 |
+
|
| 14 |
+
response = client.predict(
|
| 15 |
+
user_prompt, # str in 'User sent this' Textbox component
|
| 16 |
+
api_name="/infer"
|
| 17 |
+
)
|
| 18 |
+
return response
|
| 19 |
|
| 20 |
from utils.gradio_helpers import parse_outputs, process_outputs
|
| 21 |
|
| 22 |
names = ['prompt', 'negative_prompt', 'subject', 'number_of_outputs', 'number_of_images_per_pose', 'randomise_poses', 'output_format', 'output_quality', 'seed']
|
| 23 |
|
| 24 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
| 25 |
+
|
| 26 |
headers = {'Content-Type': 'application/json'}
|
| 27 |
|
| 28 |
payload = {"input": {}}
|
|
|
|
| 60 |
raise gr.Error(f"Sorry, the Cog image is still processing. Try again in a bit.")
|
| 61 |
raise gr.Error(f"The submission failed! Error: {response.status_code}")
|
| 62 |
|
| 63 |
+
def main(prompt, negative_prompt, subject, number_of_outputs, number_of_images_per_pose, randomise_poses, output_format, output_quality, seed):
|
| 64 |
+
print(f"""
|
| 65 |
+
—/n
|
| 66 |
+
{prompt}
|
| 67 |
+
""")
|
| 68 |
+
is_safe = safety_check(prompt)
|
| 69 |
+
print(is_safe)
|
| 70 |
+
|
| 71 |
+
match = re.search(r'\bYes\b', is_safe)
|
| 72 |
+
|
| 73 |
+
if match:
|
| 74 |
+
status = 'Yes'
|
| 75 |
+
else:
|
| 76 |
+
status = None
|
| 77 |
+
|
| 78 |
+
if status == "Yes" :
|
| 79 |
+
raise gr.Error("Don't ask for such things.")
|
| 80 |
+
else:
|
| 81 |
+
results = predict(prompt, negative_prompt, subject, number_of_outputs, number_of_images_per_pose, randomise_poses, output_format, output_quality, seed)
|
| 82 |
+
|
| 83 |
title = "Demo for consistent-character cog image by fofr"
|
| 84 |
description = "Create images of a given character in different poses • running cog image by fofr"
|
| 85 |
|
|
|
|
| 155 |
outputs = [consistent_results]
|
| 156 |
|
| 157 |
submit_btn.click(
|
| 158 |
+
fn = main,
|
| 159 |
inputs = inputs,
|
| 160 |
outputs = outputs,
|
| 161 |
show_api = False
|