Download app.py from aus201111/AUS: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/aus201111/AUS/resolve/main/app.py
- Command line
-
hf download hf://spaces/aus201111/AUS/app.py
-
curl -L -o app.py https://huggingface.co/spaces/aus201111/AUS/resolve/main/app.py
857 Bytes
| import os | |
| import requests | |
| import gradio as gr | |
| API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" | |
| headers = { | |
| "Authorization": f"Bearer {os.getenv('HF_TOKEN')}" | |
| } | |
| def generate_image(prompt): | |
| response = requests.post( | |
| API_URL, | |
| headers=headers, | |
| json={"inputs": prompt} | |
| ) | |
| if response.status_code != 200: | |
| return None, f"Error {response.status_code}: {response.text}" | |
| image_path = "output.png" | |
| with open(image_path, "wb") as f: | |
| f.write(response.content) | |
| return image_path, "Image generated successfully" | |
| demo = gr.Interface( | |
| fn=generate_image, | |
| inputs=gr.Textbox(label="Image Prompt"), | |
| outputs=[ | |
| gr.Image(label="Generated Image"), | |
| gr.Textbox(label="Status") | |
| ], | |
| title="AUS AI Image Generator" | |
| ) | |
| demo.launch() |