Spaces:
Sleeping
Sleeping
File size: 2,061 Bytes
41b451d 6d9c208 41b451d 9b17b37 6d9c208 9b17b37 6d9c208 9b17b37 41b451d 9b17b37 6d9c208 9b17b37 41b451d 9b17b37 41b451d 9b17b37 41b451d 6d9c208 41b451d 9b17b37 41b451d 9b17b37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import gradio as gr
import requests
import random
import os
def process(prompt):
"""
Processes the user's text prompt and generates an image using Pollinations API,
while enforcing universal facts and realism in the output.
"""
# Universal fact / negative guidance prompt
universal_prompt = (
"Make it realistic, consistent with universal facts, and physically possible. "
"Don't generate blurry, low quality, distorted, watermark, text, cropped, "
"deformed, bad anatomy, extra limbs, missing limbs, duplicate objects, pixelated, "
"ugly, disfigured, grainy, noisy, extra moons, duplicate moons, impossible physics."
)
# Combine user prompt with universal guidance
final_prompt = f"{prompt}. {universal_prompt}"
# Generate filename
filename = str(random.randint(111111111, 999999999)) + ".png"
file_path = os.path.join(os.path.dirname(__file__), filename)
# Build API request
api_url = (
"https://image.pollinations.ai/prompt/"
+ final_prompt.replace(" ", "%20")
+ "?model=flux-realism"
+ "&width=2048&height=2048"
+ "&nologo=true"
+ "&seed=" + str(random.randint(0, 999999999))
)
response = requests.get(api_url)
if response.status_code == 200:
with open(file_path, "wb") as f:
f.write(response.content)
return file_path
else:
return f"Error: Could not retrieve image. Status code: {response.status_code}"
# Define the Gradio interface
title = "Pollinations Image Generator"
description = "This app generates images from text using the Pollinations API."
article = "Note: Universal facts and realism are enforced in the generated images."
iface = gr.Interface(
fn=process,
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt"),
outputs=gr.Image(type="filepath", label="Generated Image"),
title=title,
description=description,
article=article
)
iface.launch(server_name="0.0.0.0", server_port=7860, pwa=True) |