Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,44 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import subprocess
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Available checkpoints: nvidia/Cosmos-Predict2-2B-Text2Image, nvidia/Cosmos-Predict2-14B-Text2Image
|
| 14 |
model_id = "diffusers-internal-dev/ct2i-14B"
|
| 15 |
|
| 16 |
# Load the pipeline once to avoid repeated loading
|
| 17 |
-
|
| 18 |
-
pipe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
@spaces.GPU
|
| 21 |
def generate_image(prompt, negative_prompt, seed, randomize_seed):
|
|
@@ -62,7 +85,7 @@ with gr.Blocks() as demo:
|
|
| 62 |
with gr.Row():
|
| 63 |
randomize_seed_checkbox = gr.Checkbox(
|
| 64 |
label="Randomize Seed",
|
| 65 |
-
value=TRue
|
| 66 |
)
|
| 67 |
seed_input = gr.Slider(
|
| 68 |
minimum=0,
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
+
# Ensure we're in the right directory and install diffusers
|
| 6 |
+
try:
|
| 7 |
+
os.chdir('diffusers_repo')
|
| 8 |
+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-e', '.'])
|
| 9 |
+
print("Successfully installed diffusers from local repository")
|
| 10 |
+
except Exception as e:
|
| 11 |
+
print(f"Installation error: {e}")
|
| 12 |
+
# Fallback to standard diffusers installation
|
| 13 |
+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'diffusers'])
|
| 14 |
|
| 15 |
+
# Add the current directory to Python path if needed
|
| 16 |
+
if os.getcwd() not in sys.path:
|
| 17 |
+
sys.path.insert(0, os.getcwd())
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
import gradio as gr
|
| 21 |
+
import spaces
|
| 22 |
+
import torch
|
| 23 |
+
from diffusers import CosmosTextToImagePipeline
|
| 24 |
+
import random
|
| 25 |
+
print("All imports successful")
|
| 26 |
+
except ImportError as e:
|
| 27 |
+
print(f"Import error: {e}")
|
| 28 |
+
print("Please ensure all required packages are installed")
|
| 29 |
+
sys.exit(1)
|
| 30 |
|
| 31 |
# Available checkpoints: nvidia/Cosmos-Predict2-2B-Text2Image, nvidia/Cosmos-Predict2-14B-Text2Image
|
| 32 |
model_id = "diffusers-internal-dev/ct2i-14B"
|
| 33 |
|
| 34 |
# Load the pipeline once to avoid repeated loading
|
| 35 |
+
try:
|
| 36 |
+
pipe = CosmosTextToImagePipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
|
| 37 |
+
pipe.to("cuda")
|
| 38 |
+
print("Pipeline loaded successfully")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"Error loading pipeline: {e}")
|
| 41 |
+
sys.exit(1)
|
| 42 |
|
| 43 |
@spaces.GPU
|
| 44 |
def generate_image(prompt, negative_prompt, seed, randomize_seed):
|
|
|
|
| 85 |
with gr.Row():
|
| 86 |
randomize_seed_checkbox = gr.Checkbox(
|
| 87 |
label="Randomize Seed",
|
| 88 |
+
value=True # Fixed: was "TRue"
|
| 89 |
)
|
| 90 |
seed_input = gr.Slider(
|
| 91 |
minimum=0,
|