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.")