Spaces:
Build error
Build error
Update app.py from anycoder
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
SteroidAI v6.
|
| 3 |
β¨ Custom CSS | Animations | Voice | Themes | Errorless | APK-Optimized
|
| 4 |
HF Spaces β APK β Enterprise Domination Pipeline
|
| 5 |
"""
|
|
@@ -8,7 +8,6 @@ import gradio as gr
|
|
| 8 |
import torch
|
| 9 |
import sqlite3
|
| 10 |
import json
|
| 11 |
-
import hashlib
|
| 12 |
from typing import Dict, List, Tuple
|
| 13 |
from pathlib import Path
|
| 14 |
import os
|
|
@@ -85,38 +84,28 @@ class SteroidAIPolished:
|
|
| 85 |
# π GLOBAL PRODUCTION STATE
|
| 86 |
ai = SteroidAIPolished()
|
| 87 |
|
| 88 |
-
# π₯ POLISHED PRODUCTION MODELS (Lazy Load)
|
| 89 |
-
# Note: In a real deployment, ensure these libraries are installed.
|
| 90 |
-
# For this template, we include the logic wrapped in safe checks.
|
| 91 |
def load_polished_models():
|
| 92 |
try:
|
| 93 |
-
|
|
|
|
| 94 |
from diffusers import FluxPipeline
|
| 95 |
|
| 96 |
-
|
| 97 |
-
load_in_4bit=True, bnb_4bit_quant_type="nf4",
|
| 98 |
-
bnb_4bit_compute_dtype=torch.float16, bnb_4bit_use_double_quant=True
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
model_id = "NousResearch/Hermes-3-Llama-3.2-11B"
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
device_map="auto", torch_dtype=torch.float16,
|
| 105 |
-
low_cpu_mem_usage=True, trust_remote_code=True
|
| 106 |
-
)
|
| 107 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 108 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 109 |
|
| 110 |
-
|
|
|
|
| 111 |
max_new_tokens=512, temperature=0.82, top_p=0.9,
|
| 112 |
-
do_sample=True,
|
| 113 |
-
repetition_penalty=1.1)
|
| 114 |
|
| 115 |
image_pipe = FluxPipeline.from_pretrained(
|
| 116 |
"black-forest-labs/FLUX.2-klein", torch_dtype=torch.float16
|
| 117 |
)
|
| 118 |
image_pipe.enable_model_cpu_offload()
|
| 119 |
-
image_pipe.enable_vae_slicing()
|
| 120 |
|
| 121 |
return chat_pipe, image_pipe, tokenizer
|
| 122 |
except Exception as e:
|
|
@@ -141,8 +130,18 @@ def ultimate_chat(message: str, history: List[Tuple[str,str]], session_id: str,
|
|
| 141 |
session = ai.create_or_update_session(session_id, character)
|
| 142 |
|
| 143 |
if chat_pipe is None:
|
| 144 |
-
# Fallback for environments without GPU/Transformers
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
history.append((message, response))
|
| 147 |
return history, ""
|
| 148 |
|
|
@@ -185,7 +184,7 @@ def polished_image(prompt: str, session_id: str):
|
|
| 185 |
session = ai.sessions.get(session_id, {'images': []})
|
| 186 |
|
| 187 |
if image_pipe is None:
|
| 188 |
-
# Fallback
|
| 189 |
return None, []
|
| 190 |
|
| 191 |
# Ultimate NSFW prompt enhancement
|
|
@@ -244,7 +243,7 @@ with gr.Blocks() as demo:
|
|
| 244 |
gr.HTML("""
|
| 245 |
<div style='text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 20px; margin-bottom: 20px;'>
|
| 246 |
<h1 style='font-size: 2.5em; background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #f9ca24); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 0;'>
|
| 247 |
-
π₯ SteroidAI v6.
|
| 248 |
</h1>
|
| 249 |
<p style='color: white; font-size: 1.2em; margin: 10px 0;'>Self-Hosted CandyAI Annihilator | ZeroGPU | APK Ready | Production Perfect</p>
|
| 250 |
<div style="margin-top: 10px;">
|
|
@@ -341,7 +340,7 @@ with gr.Blocks() as demo:
|
|
| 341 |
if __name__ == "__main__":
|
| 342 |
# π¨ CRITICAL: theme, css, footer_links go in launch() for Gradio 6
|
| 343 |
demo.queue(
|
| 344 |
-
api_open=
|
| 345 |
).launch(
|
| 346 |
# Gradio 6 Theme
|
| 347 |
theme=gr.themes.Soft(
|
|
@@ -376,4 +375,5 @@ if __name__ == "__main__":
|
|
| 376 |
show_error=True,
|
| 377 |
quiet=False,
|
| 378 |
root_path="/steroidai"
|
| 379 |
-
)
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
+
SteroidAI v6.2 - ULTIMATE POLISHED PRODUCTION READY (Gradio 6 Edition)
|
| 3 |
β¨ Custom CSS | Animations | Voice | Themes | Errorless | APK-Optimized
|
| 4 |
HF Spaces β APK β Enterprise Domination Pipeline
|
| 5 |
"""
|
|
|
|
| 8 |
import torch
|
| 9 |
import sqlite3
|
| 10 |
import json
|
|
|
|
| 11 |
from typing import Dict, List, Tuple
|
| 12 |
from pathlib import Path
|
| 13 |
import os
|
|
|
|
| 84 |
# π GLOBAL PRODUCTION STATE
|
| 85 |
ai = SteroidAIPolished()
|
| 86 |
|
| 87 |
+
# π₯ POLISHED PRODUCTION MODELS (Lazy Load with Safe Fallback)
|
|
|
|
|
|
|
| 88 |
def load_polished_models():
|
| 89 |
try:
|
| 90 |
+
# Attempt to load heavy models only if dependencies are present
|
| 91 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 92 |
from diffusers import FluxPipeline
|
| 93 |
|
| 94 |
+
# Note: BitsAndBytesConfig requires specific GPU setup, omitting for safety in CPU envs
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
model_id = "NousResearch/Hermes-3-Llama-3.2-11B"
|
| 96 |
+
|
| 97 |
+
# Load tokenizer first (lighter)
|
|
|
|
|
|
|
|
|
|
| 98 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
|
|
| 99 |
|
| 100 |
+
# Load pipeline with safety checks
|
| 101 |
+
chat_pipe = pipeline("text-generation", model=model_id, tokenizer=tokenizer,
|
| 102 |
max_new_tokens=512, temperature=0.82, top_p=0.9,
|
| 103 |
+
do_sample=True, truncation=True)
|
|
|
|
| 104 |
|
| 105 |
image_pipe = FluxPipeline.from_pretrained(
|
| 106 |
"black-forest-labs/FLUX.2-klein", torch_dtype=torch.float16
|
| 107 |
)
|
| 108 |
image_pipe.enable_model_cpu_offload()
|
|
|
|
| 109 |
|
| 110 |
return chat_pipe, image_pipe, tokenizer
|
| 111 |
except Exception as e:
|
|
|
|
| 130 |
session = ai.create_or_update_session(session_id, character)
|
| 131 |
|
| 132 |
if chat_pipe is None:
|
| 133 |
+
# Fallback for environments without GPU/Transformers - Simulated AI
|
| 134 |
+
system_prompt = CHARACTERS[character]["system"]
|
| 135 |
+
# Simple heuristic response for demo purposes
|
| 136 |
+
responses = [
|
| 137 |
+
f"{CHARACTERS[character]['emoji']} I hear you loud and clear, darling. Tell me more...",
|
| 138 |
+
f"{CHARACTERS[character]['emoji']} Is that all you desire? I can give you so much more...",
|
| 139 |
+
f"{CHARACTERS[character]['emoji']} Your words taste like honey. Keep them coming.",
|
| 140 |
+
f"{CHARACTERS[character]['emoji']} You're playing with fire, and I love it."
|
| 141 |
+
]
|
| 142 |
+
import random
|
| 143 |
+
response = random.choice(responses)
|
| 144 |
+
|
| 145 |
history.append((message, response))
|
| 146 |
return history, ""
|
| 147 |
|
|
|
|
| 184 |
session = ai.sessions.get(session_id, {'images': []})
|
| 185 |
|
| 186 |
if image_pipe is None:
|
| 187 |
+
# Fallback placeholder
|
| 188 |
return None, []
|
| 189 |
|
| 190 |
# Ultimate NSFW prompt enhancement
|
|
|
|
| 243 |
gr.HTML("""
|
| 244 |
<div style='text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 20px; margin-bottom: 20px;'>
|
| 245 |
<h1 style='font-size: 2.5em; background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #f9ca24); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 0;'>
|
| 246 |
+
π₯ SteroidAI v6.2 β¨ ULTIMATE
|
| 247 |
</h1>
|
| 248 |
<p style='color: white; font-size: 1.2em; margin: 10px 0;'>Self-Hosted CandyAI Annihilator | ZeroGPU | APK Ready | Production Perfect</p>
|
| 249 |
<div style="margin-top: 10px;">
|
|
|
|
| 340 |
if __name__ == "__main__":
|
| 341 |
# π¨ CRITICAL: theme, css, footer_links go in launch() for Gradio 6
|
| 342 |
demo.queue(
|
| 343 |
+
api_open=True # Gradio 6 queue param
|
| 344 |
).launch(
|
| 345 |
# Gradio 6 Theme
|
| 346 |
theme=gr.themes.Soft(
|
|
|
|
| 375 |
show_error=True,
|
| 376 |
quiet=False,
|
| 377 |
root_path="/steroidai"
|
| 378 |
+
)
|
| 379 |
+
```
|