Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,114 +1,14 @@
|
|
| 1 |
import os
|
| 2 |
-
import sys
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
print("=== ENVIRONMENT DEBUG INFO ===")
|
| 8 |
-
print(f"Python executable: {sys.executable}")
|
| 9 |
-
print(f"Python version: {sys.version}")
|
| 10 |
-
print(f"Current working directory: {os.getcwd()}")
|
| 11 |
-
print(f"Python path: {sys.path[:3]}...") # First 3 entries
|
| 12 |
-
|
| 13 |
-
# Check if we can find pip
|
| 14 |
-
try:
|
| 15 |
-
pip_result = subprocess.run([sys.executable, '-m', 'pip', '--version'],
|
| 16 |
-
capture_output=True, text=True)
|
| 17 |
-
print(f"Pip version: {pip_result.stdout.strip()}")
|
| 18 |
-
except Exception as e:
|
| 19 |
-
print(f"Pip check failed: {e}")
|
| 20 |
-
|
| 21 |
-
# List contents of current directory
|
| 22 |
-
print(f"Directory contents: {os.listdir('.')}")
|
| 23 |
-
if os.path.exists('diffusers_repo'):
|
| 24 |
-
print("✓ diffusers_repo found")
|
| 25 |
-
else:
|
| 26 |
-
print("✗ diffusers_repo NOT found")
|
| 27 |
-
print("===============================")
|
| 28 |
-
|
| 29 |
-
print_env_info()
|
| 30 |
-
|
| 31 |
-
# Install diffusers from local repository
|
| 32 |
-
def install_diffusers():
|
| 33 |
-
try:
|
| 34 |
-
# Change to diffusers repo directory
|
| 35 |
-
original_dir = os.getcwd()
|
| 36 |
-
|
| 37 |
-
if not os.path.exists('diffusers_repo'):
|
| 38 |
-
print("ERROR: diffusers_repo directory not found!")
|
| 39 |
-
return False
|
| 40 |
-
|
| 41 |
-
os.chdir('diffusers_repo')
|
| 42 |
-
print(f"Changed to directory: {os.getcwd()}")
|
| 43 |
-
|
| 44 |
-
# Use the exact same Python executable for pip
|
| 45 |
-
python_exe = sys.executable
|
| 46 |
-
print(f"Using Python executable: {python_exe}")
|
| 47 |
-
|
| 48 |
-
# Install in editable mode with verbose output
|
| 49 |
-
cmd = [python_exe, '-m', 'pip', 'install', '.', '--verbose']
|
| 50 |
-
print(f"Running command: {' '.join(cmd)}")
|
| 51 |
-
|
| 52 |
-
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 53 |
-
print("Installation stdout:", result.stdout[-1000:]) # Last 1000 chars
|
| 54 |
-
if result.stderr:
|
| 55 |
-
print("Installation stderr:", result.stderr[-1000:]) # Last 1000 chars
|
| 56 |
-
|
| 57 |
-
# Change back to original directory
|
| 58 |
-
os.chdir(original_dir)
|
| 59 |
-
|
| 60 |
-
# Add diffusers_repo to Python path
|
| 61 |
-
diffusers_path = os.path.join(original_dir, 'diffusers_repo')
|
| 62 |
-
if diffusers_path not in sys.path:
|
| 63 |
-
sys.path.insert(0, diffusers_path)
|
| 64 |
-
print(f"Added to Python path: {diffusers_path}")
|
| 65 |
-
|
| 66 |
-
# Test if we can import after installation
|
| 67 |
-
try:
|
| 68 |
-
import diffusers
|
| 69 |
-
print(f"✓ Successfully imported diffusers from: {diffusers.__file__}")
|
| 70 |
-
return True
|
| 71 |
-
except ImportError as e:
|
| 72 |
-
print(f"✗ Failed to import diffusers after installation: {e}")
|
| 73 |
-
return False
|
| 74 |
-
|
| 75 |
-
except Exception as e:
|
| 76 |
-
print(f"Installation failed with exception: {e}")
|
| 77 |
-
return False
|
| 78 |
-
|
| 79 |
-
# Attempt installation
|
| 80 |
-
print("Starting diffusers installation...")
|
| 81 |
-
if not install_diffusers():
|
| 82 |
-
print("Failed to install local diffusers, exiting...")
|
| 83 |
-
sys.exit(1)
|
| 84 |
-
else:
|
| 85 |
-
print("✓ Local diffusers installation successful!")
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
import spaces
|
| 93 |
-
print("✓ Spaces imported")
|
| 94 |
-
import torch
|
| 95 |
-
print("✓ Torch imported")
|
| 96 |
-
from diffusers import CosmosTextToImagePipeline
|
| 97 |
-
print("✓ CosmosTextToImagePipeline imported")
|
| 98 |
-
import random
|
| 99 |
-
print("✓ Random imported")
|
| 100 |
-
print("All imports successful!")
|
| 101 |
-
except ImportError as e:
|
| 102 |
-
print(f"✗ Import failed: {e}")
|
| 103 |
-
print("Checking installed packages...")
|
| 104 |
-
try:
|
| 105 |
-
result = subprocess.run([sys.executable, '-m', 'pip', 'list'],
|
| 106 |
-
capture_output=True, text=True)
|
| 107 |
-
print("Installed packages:")
|
| 108 |
-
print(result.stdout)
|
| 109 |
-
except:
|
| 110 |
-
pass
|
| 111 |
-
sys.exit(1)
|
| 112 |
|
| 113 |
# Available checkpoints: nvidia/Cosmos-Predict2-2B-Text2Image, nvidia/Cosmos-Predict2-14B-Text2Image
|
| 114 |
model_id = "diffusers-internal-dev/ct2i-14B"
|
|
@@ -162,7 +62,7 @@ with gr.Blocks() as demo:
|
|
| 162 |
with gr.Row():
|
| 163 |
randomize_seed_checkbox = gr.Checkbox(
|
| 164 |
label="Randomize Seed",
|
| 165 |
-
value=
|
| 166 |
)
|
| 167 |
seed_input = gr.Slider(
|
| 168 |
minimum=0,
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import subprocess
|
| 3 |
|
| 4 |
+
os.chdir('diffusers_repo')
|
| 5 |
+
subprocess.check_call(['pip', 'install', '.'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import spaces
|
| 9 |
+
import torch
|
| 10 |
+
from diffusers import CosmosTextToImagePipeline
|
| 11 |
+
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Available checkpoints: nvidia/Cosmos-Predict2-2B-Text2Image, nvidia/Cosmos-Predict2-14B-Text2Image
|
| 14 |
model_id = "diffusers-internal-dev/ct2i-14B"
|
|
|
|
| 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,
|