anaspro commited on
Commit
c6cb208
·
1 Parent(s): f9a37de

Fix model loading - load on startup not during chat

Browse files

- Move model loading to application startup instead of inside @spaces.GPU decorator
- Prevents timeout issues during chat by pre-loading the 20B model
- Model loads once at startup, not on every message
- Fixes 'processing' timeout error shown in interface

Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -132,10 +132,9 @@ def chat(message, history):
132
  """Main chat function with improved error handling and conversation management"""
133
  global model, tokenizer
134
 
135
- # Load model if not already loaded
136
  if model is None or tokenizer is None:
137
- if not load_model():
138
- return "❌ عذراً، حدث خطأ في تحميل النموذج. يرجى المحاولة مرة أخرى."
139
 
140
  try:
141
  # ======================================================
@@ -313,6 +312,12 @@ def create_interface():
313
 
314
  return demo
315
 
 
 
 
 
 
 
316
  # Create the interface
317
  demo = create_interface()
318
 
 
132
  """Main chat function with improved error handling and conversation management"""
133
  global model, tokenizer
134
 
135
+ # Check if model is loaded
136
  if model is None or tokenizer is None:
137
+ return "❌ عذراً، النموذج لم يتم تحميله بعد. يرجى الانتظار قليلاً والمحاولة مرة أخرى."
 
138
 
139
  try:
140
  # ======================================================
 
312
 
313
  return demo
314
 
315
+ # ======================================================
316
+ # Load model on startup (before creating interface)
317
+ # ======================================================
318
+ logger.info("🚀 Starting application - loading model...")
319
+ load_model()
320
+
321
  # Create the interface
322
  demo = create_interface()
323