Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -203,17 +203,60 @@
|
|
| 203 |
# interface.launch(debug=True)
|
| 204 |
#!/usr/bin/env python
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
#!/usr/bin/env python
|
| 207 |
|
| 208 |
import os
|
| 209 |
import torch
|
| 210 |
-
|
|
|
|
| 211 |
|
| 212 |
-
#
|
|
|
|
|
|
|
|
|
|
| 213 |
torch.set_num_threads(4)
|
| 214 |
|
| 215 |
-
#
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
# interface.launch(debug=True)
|
| 204 |
#!/usr/bin/env python
|
| 205 |
|
| 206 |
+
# #!/usr/bin/env python
|
| 207 |
+
|
| 208 |
+
# import os
|
| 209 |
+
# import torch
|
| 210 |
+
# from multimodal_app import create_interface
|
| 211 |
+
|
| 212 |
+
# # Optional: Set torch threads to limit CPU usage
|
| 213 |
+
# torch.set_num_threads(4)
|
| 214 |
+
|
| 215 |
+
# # Create and launch the interface
|
| 216 |
+
# demo = create_interface()
|
| 217 |
+
# demo.queue() # Enable queuing for better handling of multiple requests
|
| 218 |
+
# demo.launch()
|
| 219 |
#!/usr/bin/env python
|
| 220 |
|
| 221 |
import os
|
| 222 |
import torch
|
| 223 |
+
import sys
|
| 224 |
+
import argparse
|
| 225 |
|
| 226 |
+
# Set environment variables for better compatibility
|
| 227 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 228 |
+
|
| 229 |
+
# Set torch threads to limit CPU usage
|
| 230 |
torch.set_num_threads(4)
|
| 231 |
|
| 232 |
+
# Parse command line arguments
|
| 233 |
+
parser = argparse.ArgumentParser(description="Multimodal Image Description App")
|
| 234 |
+
parser.add_argument("--peft-model", type=str, default="/content/drive/MyDrive/V6_Checkpoints/Epoch_peft_1",
|
| 235 |
+
help="Path to PEFT model")
|
| 236 |
+
parser.add_argument("--port", type=int, default=7860,
|
| 237 |
+
help="Port to run the server on")
|
| 238 |
+
args = parser.parse_args()
|
| 239 |
|
| 240 |
+
try:
|
| 241 |
+
from multimodal_app import create_interface, load_model
|
| 242 |
+
|
| 243 |
+
# Preload the model with PEFT path
|
| 244 |
+
print(f"Preloading model with PEFT path: {args.peft_model}")
|
| 245 |
+
load_model(args.peft_model)
|
| 246 |
+
|
| 247 |
+
# Create and launch the interface
|
| 248 |
+
demo = create_interface()
|
| 249 |
+
|
| 250 |
+
# Launch with proper settings for stability
|
| 251 |
+
demo.launch(
|
| 252 |
+
share=False, # Set to True if you want a public link
|
| 253 |
+
debug=True, # Enable debug for better error messages
|
| 254 |
+
server_name="0.0.0.0", # Listen on all interfaces
|
| 255 |
+
server_port=args.port, # Port from arguments
|
| 256 |
+
show_api=False # Hide API docs for simplicity
|
| 257 |
+
)
|
| 258 |
+
except Exception as e:
|
| 259 |
+
print(f"Error starting application: {e}")
|
| 260 |
+
import traceback
|
| 261 |
+
traceback.print_exc()
|
| 262 |
+
sys.exit(1)
|