Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -48,14 +48,16 @@ def load_model(model_name: str):
|
|
| 48 |
model_config = MODELS_SPECIFIC_CONFIGS.get(model_name, {})
|
| 49 |
model = build_interfuser_model(model_config)
|
| 50 |
if not os.path.exists(weights_path):
|
| 51 |
-
gr.Warning
|
|
|
|
| 52 |
else:
|
| 53 |
try:
|
| 54 |
state_dic = torch.load(weights_path, map_location=device, weights_only=True)
|
| 55 |
model.load_state_dict(state_dic)
|
| 56 |
print(f"تم تحميل أوزان النموذج '{model_name}' بنجاح.")
|
| 57 |
except Exception as e:
|
| 58 |
-
gr.Warning
|
|
|
|
| 59 |
model.to(device)
|
| 60 |
model.eval()
|
| 61 |
return model, f"تم تحميل نموذج: {model_name}"
|
|
@@ -232,5 +234,5 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), cs
|
|
| 232 |
# ==============================================================================
|
| 233 |
if __name__ == "__main__":
|
| 234 |
if not available_models:
|
| 235 |
-
print("تحذير: لم يتم العثور على أي ملفات نماذج (.pth) في مجلد 'model
|
| 236 |
-
demo.queue().launch(debug=True, share=True) # share=True لإنشاء رابط عام مؤقت
|
|
|
|
| 48 |
model_config = MODELS_SPECIFIC_CONFIGS.get(model_name, {})
|
| 49 |
model = build_interfuser_model(model_config)
|
| 50 |
if not os.path.exists(weights_path):
|
| 51 |
+
# استبدال gr.Warning برمي استثناء خطأ
|
| 52 |
+
raise gr.Error(f"ملف الأوزان '{weights_path}' غير موجود.")
|
| 53 |
else:
|
| 54 |
try:
|
| 55 |
state_dic = torch.load(weights_path, map_location=device, weights_only=True)
|
| 56 |
model.load_state_dict(state_dic)
|
| 57 |
print(f"تم تحميل أوزان النموذج '{model_name}' بنجاح.")
|
| 58 |
except Exception as e:
|
| 59 |
+
# استبدال gr.Warning برمي استثناء خطأ
|
| 60 |
+
raise gr.Error(f"فشل تحميل الأوزان للنموذج '{model_name}': {e}.")
|
| 61 |
model.to(device)
|
| 62 |
model.eval()
|
| 63 |
return model, f"تم تحميل نموذج: {model_name}"
|
|
|
|
| 234 |
# ==============================================================================
|
| 235 |
if __name__ == "__main__":
|
| 236 |
if not available_models:
|
| 237 |
+
print("تحذير: لم يتم العثور على أي ملفات نماذج (.pth) في مجلد 'model'.")
|
| 238 |
+
demo.queue().launch(debug=True, share=True) # share=True لإنشاء رابط عام مؤقت
|