Walmart-the-bag commited on
Commit
5550780
·
verified ·
1 Parent(s): 7044dfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import requests
3
  import json
4
  import time
5
- from better_profanity import profanity
6
 
7
  url = "https://nexra.aryahcr.cc/api/image/complements"
8
  headers = {
@@ -10,13 +10,14 @@ headers = {
10
  }
11
 
12
  profanity.load_censor_words()
 
13
 
14
  def is_nsfw(text):
15
  return profanity.contains_profanity(text)
16
 
17
  def generate_image(prompt, model):
18
  if is_nsfw(prompt):
19
- return "Error: Prompt contains inappropriate content."
20
 
21
  data = {
22
  "prompt": prompt,
@@ -30,7 +31,7 @@ def generate_image(prompt, model):
30
  image_id = response_data.get("id")
31
 
32
  if not image_id:
33
- return "Error: No image ID returned in the response."
34
 
35
  while True:
36
  status_response = requests.get(f"{url}/{image_id}")
@@ -45,23 +46,23 @@ def generate_image(prompt, model):
45
  image_url = images[0]
46
  return image_url
47
  else:
48
- return "Error: No images found in the response."
49
  elif status == "error":
50
- return "Error: Image generation failed."
51
  elif status == "not_found":
52
- return "Error: Image ID not found."
53
  elif status == "pending":
54
  time.sleep(1)
55
  else:
56
- return f"Error: Unexpected status '{status}'."
57
  else:
58
- return f"Error: Status check failed with code {status_response.status_code}."
59
  else:
60
- return f"Error: Initial request failed with code {response.status_code}."
61
  except json.JSONDecodeError:
62
- return "Error: Invalid JSON response."
63
  except Exception as e:
64
- return f"Exception occurred: {str(e)}"
65
 
66
  iface = gr.Interface(
67
  fn=generate_image,
 
2
  import requests
3
  import json
4
  import time
5
+ from better_profanity import profanity
6
 
7
  url = "https://nexra.aryahcr.cc/api/image/complements"
8
  headers = {
 
10
  }
11
 
12
  profanity.load_censor_words()
13
+ no_nsfw_image_path = "no_nsfw.png"
14
 
15
  def is_nsfw(text):
16
  return profanity.contains_profanity(text)
17
 
18
  def generate_image(prompt, model):
19
  if is_nsfw(prompt):
20
+ return no_nsfw_image_path
21
 
22
  data = {
23
  "prompt": prompt,
 
31
  image_id = response_data.get("id")
32
 
33
  if not image_id:
34
+ return no_nsfw_image_path
35
 
36
  while True:
37
  status_response = requests.get(f"{url}/{image_id}")
 
46
  image_url = images[0]
47
  return image_url
48
  else:
49
+ return no_nsfw_image_path
50
  elif status == "error":
51
+ return no_nsfw_image_path
52
  elif status == "not_found":
53
+ return no_nsfw_image_path
54
  elif status == "pending":
55
  time.sleep(1)
56
  else:
57
+ return no_nsfw_image_path
58
  else:
59
+ return no_nsfw_image_path
60
  else:
61
+ return no_nsfw_image_path
62
  except json.JSONDecodeError:
63
+ return no_nsfw_image_path
64
  except Exception as e:
65
+ return no_nsfw_image_path
66
 
67
  iface = gr.Interface(
68
  fn=generate_image,