multimodalart HF Staff commited on
Commit
4d28da6
Β·
verified Β·
1 Parent(s): 43a37a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -108
app.py CHANGED
@@ -1,114 +1,14 @@
1
  import os
2
- import sys
3
  import subprocess
4
 
5
- # Debug: Print environment information
6
- def print_env_info():
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
- # Now import required modules
88
- print("Importing required modules...")
89
- try:
90
- import gradio as gr
91
- print("βœ“ Gradio imported")
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=True # Fixed: was "TRue"
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,