Download app.py from rick1123/open: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/rick1123/open/resolve/main/app.py
- Command line
-
hf download hf://spaces/rick1123/open/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rick1123/open/resolve/main/app.py
1.31 kB
| 1 import os, gradio as gr, torch | |
| 2 from diffusers import StableDiffusion3Pipeline | |
| 3 | |
| 4 HF_TOKEN = os.environ.get("HF_TOKEN", "") | |
| 5 MODEL_ID = "stabilityai/stable-diffusion-3.5-large-turbo" | |
| 6 pipe = None | |
| 7 | |
| 8 def load_model(): | |
| 9 global pipe | |
| 10 if pipe is None: | |
| 11 pipe = StableDiffusion3Pipeline.from_pretrained(MODEL_ID, torch_dtype=torch.float16, token=HF_TO | |
| KEN).to("cuda" if torch.cuda.is_available() else "cpu") | |
| 12 return pipe | |
| 13 | |
| 14 daily_usage = {"free": 0} | |
| 15 | |
| 16 def generate(p, email="", neg="", steps=28, g=7.0): | |
| 17 if daily_usage["free"] >= 10: return None, "Limit reached! Upgrade to Pro" | |
| 18 if not email or "@" not in email: return None, "Enter email for free tier" | |
| 19 img = load_model()(p, negative_prompt=neg, num_inference_steps=int(steps), guidance_scale=g).images[ | |
| 0] | |
| 20 daily_usage["free"] += 1 | |
| 21 return img, f"Generated ({daily_usage['free']}/10 free)" | |
| 22 | |
| 23 demo = gr.Interface(fn=generate, inputs=["text", "text", "text", gr.Slider(20,50,28), gr.Slider(1,15,7)] | |
| , outputs=["image", "text"], title="RJ AI Image Studio") | |
| 24 demo.launch(server_name="0.0.0.0", server_port=7860) |