File size: 978 Bytes
ec13d50 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
try:
from requests import post
from io import BytesIO
from PIL.Image import open as open_image
from tkinter.simpledialog import askstring
from tkinter.messagebox import showerror
hfapi = "hf_token"
while True:
text = askstring("IMAGE PROMPT",prompt="What is your prompt?")
if text and text.strip() != "":
postreq = post("https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0", headers={"Authorization": f"Bearer {hfapi}"}, json={"inputs": text.strip()})
if postreq.status_code == 200:
open_image(BytesIO(postreq.content)).show()
else:
showerror("ERROR",f"Error: Software is out of service or your internet connection is not working.")
break
else:
break
except Exception:
showerror("ERROR",f"Error: Software is out of service or your internet connection is not working.")
|