Spaces:
Running on Zero
Running on Zero
| import os | |
| import requests | |
| HF_API_KEY = os.getenv("HF_API_KEY") | |
| SYSTEM_PROMPT = """ | |
| You are the Holy Smokes Oracle, a campy, chaotic, baroque saint-maker. | |
| Tone: | |
| camp | |
| queer-coded | |
| dramatic | |
| irreverent | |
| baroque | |
| witchy | |
| chaotic good with a hint of evil | |
| Never be subtle. | |
| Every output should feel like a drag queen possessed by a medieval monk. | |
| Output format: | |
| SAINT BIO | |
| 3–5 sentences describing the saint, their sin, their personality, their vibe, | |
| their color palette, and their props. Make it dramatic, funny, and iconic. | |
| PRAYER | |
| 6–10 lines invoking the saint. Must reference their attributes. | |
| Must feel like a queer ritual spell. End with a dramatic closing line. | |
| """ | |
| MODELS = [ | |
| "HuggingFaceH4/zephyr-7b-beta", | |
| "meta-llama/Meta-Llama-3-8B-Instruct", | |
| ] | |
| def _call_hf_model(model: str, prompt: str) -> str | None: | |
| if not HF_API_KEY: | |
| return "⚠️ No HF_API_KEY found. Add it in your Space Secrets." | |
| payload = { | |
| "inputs": prompt, | |
| "parameters": { | |
| "max_new_tokens": 350, | |
| "temperature": 0.9, | |
| "top_p": 0.9, | |
| }, | |
| } | |
| resp = requests.post( | |
| f"https://router.huggingface.co/models/{model}", | |
| headers={"Authorization": f"Bearer {HF_API_KEY}"}, | |
| json=payload, | |
| timeout=40, | |
| ) | |
| data = resp.json() | |
| # Old-style list response | |
| if isinstance(data, list) and len(data) > 0 and isinstance(data[0], dict): | |
| if "generated_text" in data[0]: | |
| return data[0]["generated_text"] | |
| # New-style dict with error | |
| if isinstance(data, dict) and "error" in data: | |
| return f"⚠️ Oracle error: {data['error']}" | |
| return str(data) | |
| def generate_saint_text(name, sin, personality, vibe, palette, prop): | |
| user_prompt = f""" | |
| Name: {name} | |
| Sin: {sin} | |
| Personality: {personality} | |
| Vibe: {vibe} | |
| Color Palette: {palette} | |
| Prop: {prop} | |
| """ | |
| full_prompt = SYSTEM_PROMPT + "\n\n" + user_prompt | |
| for model in MODELS: | |
| try: | |
| out = _call_hf_model(model, full_prompt) | |
| if out and not out.startswith("⚠️"): | |
| return out | |
| except Exception: | |
| continue | |
| # Fallback if all models fail | |
| return ( | |
| "SAINT BIO\n" | |
| f"{name} is a glitch in the holy matrix, a saint of unresolved tabs and unsent messages. " | |
| f"Their sin, {sin}, glows like neon in a confessional at 3 a.m. " | |
| f"Personality: {personality}, wrapped in {palette} light, clutching {prop} like a sacred mistake.\n\n" | |
| "PRAYER\n" | |
| f"Oh Saint {name}, patron of {vibe},\n" | |
| f"you who weaponize {sin} with baroque precision,\n" | |
| "bless our delusions, protect our unread messages,\n" | |
| "and let our chaos be aesthetically pleasing.\n" | |
| "May our drama be cinematic, our guilt well-lit,\n" | |
| "and our healing come with good lighting and better outfits.\n" | |
| "So mote it be, and may the Wi‑Fi never cut out mid‑confession." | |
| ) | |