Spaces:
Runtime error
Runtime error
invincible-jha
commited on
Commit
·
d28913a
1
Parent(s):
6e790f0
Force CPU-only mode and disable GPU completely
Browse files- app.py +17 -12
- interface/app.py +12 -6
app.py
CHANGED
|
@@ -7,18 +7,19 @@ from utils.log_manager import LogManager
|
|
| 7 |
|
| 8 |
def setup_environment():
|
| 9 |
"""Setup environment variables and device configuration"""
|
| 10 |
-
# Force CPU usage
|
| 11 |
-
|
| 12 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 13 |
-
device = "cpu"
|
| 14 |
-
else:
|
| 15 |
-
device = "cuda"
|
| 16 |
-
|
| 17 |
-
# Set transformers to use CPU
|
| 18 |
os.environ["TRANSFORMERS_OFFLINE"] = "1"
|
| 19 |
-
os.environ["TORCH_DEVICE"] =
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def main():
|
| 24 |
# Initialize logging
|
|
@@ -27,10 +28,13 @@ def main():
|
|
| 27 |
logger.info("Starting Mental Wellness Platform")
|
| 28 |
|
| 29 |
try:
|
| 30 |
-
# Setup environment
|
| 31 |
device = setup_environment()
|
| 32 |
logger.info(f"Using device: {device}")
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
# Load configuration
|
| 35 |
config = load_config()
|
| 36 |
logger.info("Configuration loaded successfully")
|
|
@@ -44,7 +48,8 @@ def main():
|
|
| 44 |
server_name="0.0.0.0",
|
| 45 |
server_port=7860,
|
| 46 |
show_error=True, # Show detailed error messages
|
| 47 |
-
root_path="" # Empty root path for Spaces
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
except Exception as e:
|
|
|
|
| 7 |
|
| 8 |
def setup_environment():
|
| 9 |
"""Setup environment variables and device configuration"""
|
| 10 |
+
# Force CPU usage and disable GPU
|
| 11 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
os.environ["TRANSFORMERS_OFFLINE"] = "1"
|
| 13 |
+
os.environ["TORCH_DEVICE"] = "cpu"
|
| 14 |
+
|
| 15 |
+
# Disable CUDA initialization
|
| 16 |
+
torch.cuda.is_available = lambda: False
|
| 17 |
|
| 18 |
+
# Set PyTorch to use CPU
|
| 19 |
+
if hasattr(torch, 'set_default_tensor_type'):
|
| 20 |
+
torch.set_default_tensor_type('torch.FloatTensor')
|
| 21 |
+
|
| 22 |
+
return "cpu"
|
| 23 |
|
| 24 |
def main():
|
| 25 |
# Initialize logging
|
|
|
|
| 28 |
logger.info("Starting Mental Wellness Platform")
|
| 29 |
|
| 30 |
try:
|
| 31 |
+
# Setup environment before anything else
|
| 32 |
device = setup_environment()
|
| 33 |
logger.info(f"Using device: {device}")
|
| 34 |
|
| 35 |
+
# Disable GPU memory allocation
|
| 36 |
+
torch.cuda.empty_cache()
|
| 37 |
+
|
| 38 |
# Load configuration
|
| 39 |
config = load_config()
|
| 40 |
logger.info("Configuration loaded successfully")
|
|
|
|
| 48 |
server_name="0.0.0.0",
|
| 49 |
server_port=7860,
|
| 50 |
show_error=True, # Show detailed error messages
|
| 51 |
+
root_path="", # Empty root path for Spaces
|
| 52 |
+
quiet=True # Reduce logging noise
|
| 53 |
)
|
| 54 |
|
| 55 |
except Exception as e:
|
interface/app.py
CHANGED
|
@@ -5,6 +5,11 @@ import logging
|
|
| 5 |
from utils.log_manager import LogManager
|
| 6 |
from utils.analytics_logger import AnalyticsLogger
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
class WellnessInterface:
|
| 9 |
def __init__(self, config):
|
| 10 |
self.config = config
|
|
@@ -12,10 +17,11 @@ class WellnessInterface:
|
|
| 12 |
self.logger = self.log_manager.get_agent_logger("interface")
|
| 13 |
self.analytics = AnalyticsLogger()
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
self.device =
|
| 17 |
-
self.logger.info(
|
| 18 |
|
|
|
|
| 19 |
self.setup_interface()
|
| 20 |
|
| 21 |
def setup_interface(self):
|
|
@@ -105,7 +111,7 @@ class WellnessInterface:
|
|
| 105 |
],
|
| 106 |
outputs=[
|
| 107 |
self.chatbot,
|
| 108 |
-
self.text_input
|
| 109 |
],
|
| 110 |
api_name="chat"
|
| 111 |
)
|
|
@@ -135,7 +141,7 @@ class WellnessInterface:
|
|
| 135 |
],
|
| 136 |
outputs=[
|
| 137 |
self.chatbot,
|
| 138 |
-
self.text_input
|
| 139 |
]
|
| 140 |
)
|
| 141 |
|
|
@@ -149,7 +155,7 @@ class WellnessInterface:
|
|
| 149 |
"""Process user input from various sources"""
|
| 150 |
try:
|
| 151 |
if not text and not audio and not image:
|
| 152 |
-
return history, ""
|
| 153 |
|
| 154 |
# Log the interaction start
|
| 155 |
self.analytics.log_user_interaction(
|
|
|
|
| 5 |
from utils.log_manager import LogManager
|
| 6 |
from utils.analytics_logger import AnalyticsLogger
|
| 7 |
|
| 8 |
+
# Force CPU-only mode
|
| 9 |
+
torch.cuda.is_available = lambda: False
|
| 10 |
+
if hasattr(torch, 'set_default_tensor_type'):
|
| 11 |
+
torch.set_default_tensor_type('torch.FloatTensor')
|
| 12 |
+
|
| 13 |
class WellnessInterface:
|
| 14 |
def __init__(self, config):
|
| 15 |
self.config = config
|
|
|
|
| 17 |
self.logger = self.log_manager.get_agent_logger("interface")
|
| 18 |
self.analytics = AnalyticsLogger()
|
| 19 |
|
| 20 |
+
# Ensure CPU-only operation
|
| 21 |
+
self.device = "cpu"
|
| 22 |
+
self.logger.info("Using CPU-only mode")
|
| 23 |
|
| 24 |
+
# Initialize interface
|
| 25 |
self.setup_interface()
|
| 26 |
|
| 27 |
def setup_interface(self):
|
|
|
|
| 111 |
],
|
| 112 |
outputs=[
|
| 113 |
self.chatbot,
|
| 114 |
+
self.text_input
|
| 115 |
],
|
| 116 |
api_name="chat"
|
| 117 |
)
|
|
|
|
| 141 |
],
|
| 142 |
outputs=[
|
| 143 |
self.chatbot,
|
| 144 |
+
self.text_input
|
| 145 |
]
|
| 146 |
)
|
| 147 |
|
|
|
|
| 155 |
"""Process user input from various sources"""
|
| 156 |
try:
|
| 157 |
if not text and not audio and not image:
|
| 158 |
+
return history, ""
|
| 159 |
|
| 160 |
# Log the interaction start
|
| 161 |
self.analytics.log_user_interaction(
|