PraneshJs commited on
Commit
6d9c208
·
verified ·
1 Parent(s): 9b17b37

fixed api call

Browse files
Files changed (1) hide show
  1. app.py +13 -25
app.py CHANGED
@@ -5,32 +5,21 @@ import os
5
 
6
  def process(prompt):
7
  """
8
- Processes the user's text prompt to either generate an image or display a content warning.
 
9
  """
10
 
11
- # Expanded list of restricted words (mature/unsafe content).
12
- restricted_words = [
13
- "sex", "erotic", "nude", "explicit", "porn", "xxx", "18+", "nudity", "sexual",
14
- "lewd", "obscene", "hentai", "bondage", "bdsm", "fetish", "voyeur",
15
- "masturbate", "orgasm", "gangbang", "rape", "incest", "pedophile", "child abuse",
16
- "bestiality", "prostitution", "threesome", "anal", "oral", "intercourse",
17
- "ejaculation", "cumshot", "hardcore", "softcore", "lingerie", "stripper",
18
- "dildo", "vibrator", "panty", "bra", "nipple", "genitals", "pubic", "ass", "tits",
19
- "dick", "pussy", "blowjob", "handjob", "deepthroat", "g-string", "bikini",
20
- "topless", "bottomless", "kinky", "dominant", "submissive", "sadism", "masochism",
21
- "orgies", "sexually suggestive", "vulgar"
22
- ]
23
-
24
- # Check restricted words
25
- if any(word in prompt.lower() for word in restricted_words):
26
- return "This is mature content. It's not permitted to generate images on this topic."
27
-
28
- # Add negative prompts to improve quality
29
- negative_prompt = (
30
- "blurry, low quality, distorted, watermark, text, cropped, deformed, bad anatomy, "
31
- "extra limbs, missing limbs, duplicate, pixelated, ugly, disfigured, grainy, noisy"
32
  )
33
 
 
 
 
34
  # Generate filename
35
  filename = str(random.randint(111111111, 999999999)) + ".png"
36
  file_path = os.path.join(os.path.dirname(__file__), filename)
@@ -38,12 +27,11 @@ def process(prompt):
38
  # Build API request
39
  api_url = (
40
  "https://image.pollinations.ai/prompt/"
41
- + prompt
42
  + "?model=flux-realism"
43
  + "&width=2048&height=2048"
44
  + "&nologo=true"
45
  + "&seed=" + str(random.randint(0, 999999999))
46
- + "&negative_prompt=" + negative_prompt.replace(" ", "%20")
47
  )
48
 
49
  response = requests.get(api_url)
@@ -58,7 +46,7 @@ def process(prompt):
58
  # Define the Gradio interface
59
  title = "Pollinations Image Generator"
60
  description = "This app generates images from text using the Pollinations API."
61
- article = "Note: Mature content is blocked. Negative prompts are applied to avoid blurry or low-quality results."
62
 
63
  iface = gr.Interface(
64
  fn=process,
 
5
 
6
  def process(prompt):
7
  """
8
+ Processes the user's text prompt and generates an image using Pollinations API,
9
+ while enforcing universal facts and realism in the output.
10
  """
11
 
12
+ # Universal fact / negative guidance prompt
13
+ universal_prompt = (
14
+ "Make it realistic, consistent with universal facts, and physically possible. "
15
+ "Don't generate blurry, low quality, distorted, watermark, text, cropped, "
16
+ "deformed, bad anatomy, extra limbs, missing limbs, duplicate objects, pixelated, "
17
+ "ugly, disfigured, grainy, noisy, extra moons, duplicate moons, impossible physics."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  )
19
 
20
+ # Combine user prompt with universal guidance
21
+ final_prompt = f"{prompt}. {universal_prompt}"
22
+
23
  # Generate filename
24
  filename = str(random.randint(111111111, 999999999)) + ".png"
25
  file_path = os.path.join(os.path.dirname(__file__), filename)
 
27
  # Build API request
28
  api_url = (
29
  "https://image.pollinations.ai/prompt/"
30
+ + final_prompt.replace(" ", "%20")
31
  + "?model=flux-realism"
32
  + "&width=2048&height=2048"
33
  + "&nologo=true"
34
  + "&seed=" + str(random.randint(0, 999999999))
 
35
  )
36
 
37
  response = requests.get(api_url)
 
46
  # Define the Gradio interface
47
  title = "Pollinations Image Generator"
48
  description = "This app generates images from text using the Pollinations API."
49
+ article = "Note: Universal facts and realism are enforced in the generated images."
50
 
51
  iface = gr.Interface(
52
  fn=process,