Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import DDPMPipeline
|
| 3 |
+
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# --- CONFIGURATION ---
|
| 8 |
+
MODEL_ID = "FlameF0X/Stable-Lime-v1.0"
|
| 9 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
+
|
| 11 |
+
print(f"🍋 Initializing Stable-Lime Protocol on {DEVICE}...")
|
| 12 |
+
|
| 13 |
+
# --- LOAD MODEL ---
|
| 14 |
+
try:
|
| 15 |
+
# Load the pipeline directly from your Hub repo
|
| 16 |
+
pipeline = DDPMPipeline.from_pretrained(MODEL_ID)
|
| 17 |
+
pipeline.to(DEVICE)
|
| 18 |
+
print("✅ Lime Status: ONLINE")
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"❌ CRITICAL FAILURE: Could not load the Lime. Error: {e}")
|
| 21 |
+
# Fallback to avoid crashing the space immediately, allows debugging
|
| 22 |
+
pipeline = None
|
| 23 |
+
|
| 24 |
+
def generate_lime():
|
| 25 |
+
"""
|
| 26 |
+
The core inference function.
|
| 27 |
+
Summons a lime from the latent void.
|
| 28 |
+
"""
|
| 29 |
+
if pipeline is None:
|
| 30 |
+
return None, "Error: Model failed to load. Check logs."
|
| 31 |
+
|
| 32 |
+
print("🍋 Generating new specimen...")
|
| 33 |
+
# Generate the image
|
| 34 |
+
# num_inference_steps=50 is a good balance for speed/quality on CPU Spaces
|
| 35 |
+
image = pipeline(num_inference_steps=50).images[0]
|
| 36 |
+
|
| 37 |
+
return image, "✨ Specimen Acquired."
|
| 38 |
+
|
| 39 |
+
# --- CUSTOM CSS ---
|
| 40 |
+
# Giving it that dark, research-lab vibe from your screenshots
|
| 41 |
+
custom_css = """
|
| 42 |
+
body { background-color: #0d0d0d; color: #e0e0e0; font-family: 'Courier New', monospace; }
|
| 43 |
+
.gradio-container { max-width: 700px !important; margin-top: 40px !important; }
|
| 44 |
+
h1 { color: #ff5722; text-align: center; font-weight: bold; letter-spacing: 2px; }
|
| 45 |
+
.lime-btn { background-color: #32CD32 !important; color: #000 !important; font-weight: bold; border: 1px solid #32CD32; }
|
| 46 |
+
.lime-btn:hover { box-shadow: 0 0 15px #32CD32; }
|
| 47 |
+
.footer { text-align: center; margin-top: 20px; font-size: 0.8em; color: #666; }
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
# --- THE UI ---
|
| 51 |
+
with gr.Blocks(css=custom_css, title="Stable-Lime v1.0") as demo:
|
| 52 |
+
gr.HTML("<h1>> STABLE-LIME v1.0 <</h1>")
|
| 53 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
with gr.Column():
|
| 56 |
+
lime_output = gr.Image(label="Generated Artifact", type="pil", elem_id="lime-out")
|
| 57 |
+
status_text = gr.Textbox(label="System Log", value="System Ready. Awaiting Input.", interactive=False)
|
| 58 |
+
|
| 59 |
+
generate_btn = gr.Button("INITIALIZE GENERATION", elem_classes="lime-btn")
|
| 60 |
+
|
| 61 |
+
gr.HTML("<div class='footer'>Running on Unconditional U-Net Architecture | Powered by FlameF0X Research</div>")
|
| 62 |
+
|
| 63 |
+
# Wire up the button
|
| 64 |
+
generate_btn.click(
|
| 65 |
+
fn=generate_lime,
|
| 66 |
+
inputs=None,
|
| 67 |
+
outputs=[lime_output, status_text]
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
# Launch the app
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
demo.launch()
|