alibayram commited on
Commit
67856b9
Β·
1 Parent(s): 115be8a

space update

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -168,8 +168,20 @@ def load_model_from_file(uploaded_file):
168
  return "❌ No file uploaded"
169
 
170
  try:
 
 
 
 
 
 
 
 
 
 
 
 
171
  # Load the new model
172
- new_model, new_tokenizer, status = load_model(uploaded_file.name)
173
 
174
  # Update global variables
175
  model = new_model
@@ -179,6 +191,7 @@ def load_model_from_file(uploaded_file):
179
  return status
180
  except Exception as e:
181
  error_msg = f"❌ Failed to load uploaded model: {e}"
 
182
  model_status = error_msg
183
  return error_msg
184
 
@@ -249,7 +262,7 @@ with gr.Blocks(title="πŸ€– Usta Model Chat") as demo:
249
  load_url_btn = gr.Button("Load from URL", scale=1)
250
 
251
  with gr.Row():
252
- model_file = gr.File(label="Upload .pth file", file_types=[".pth"])
253
  load_file_btn = gr.Button("Load File", scale=1)
254
 
255
  status = gr.Textbox(label="Status", value=model_status, interactive=False)
 
168
  return "❌ No file uploaded"
169
 
170
  try:
171
+ # Check if the file path exists and is valid
172
+ file_path = uploaded_file.name if hasattr(uploaded_file, 'name') else str(uploaded_file)
173
+
174
+ # For HF Spaces compatibility, also try the upload path
175
+ if not os.path.exists(file_path) and hasattr(uploaded_file, 'orig_name'):
176
+ # Sometimes HF Spaces provides different paths
177
+ print(f"Original path not found: {file_path}")
178
+ print(f"Trying original name: {uploaded_file.orig_name}")
179
+ file_path = uploaded_file.orig_name
180
+
181
+ print(f"πŸ“ Attempting to load model from: {file_path}")
182
+
183
  # Load the new model
184
+ new_model, new_tokenizer, status = load_model(file_path)
185
 
186
  # Update global variables
187
  model = new_model
 
191
  return status
192
  except Exception as e:
193
  error_msg = f"❌ Failed to load uploaded model: {e}"
194
+ print(f"Error details: {e}")
195
  model_status = error_msg
196
  return error_msg
197
 
 
262
  load_url_btn = gr.Button("Load from URL", scale=1)
263
 
264
  with gr.Row():
265
+ model_file = gr.File(label="Upload model file (.pth, .pt, .bin)")
266
  load_file_btn = gr.Button("Load File", scale=1)
267
 
268
  status = gr.Textbox(label="Status", value=model_status, interactive=False)