Spaces:
Runtime error
Runtime error
Update app.py
Browse files77 unmodified lines787980818283848586878877 unmodified lines# Load the modelmodel = MultiTaskModel(model_name)model.load_state_dict(torch.load('safety_classifier_model.pth', map_location='cpu')) # Add map_location='cpu'model.eval()tokenizer = AutoTokenizer.from_pretrained('./tokenizer')# Create Gradio interfaceiface = gr.Interface(fn=predict_safety,77 unmodified lines7879808182838485868788899091929394959697989910077 unmodified lines# Load the modelmodel = MultiTaskModel(model_name)# Load state dict and remove 'module.' prefixesstate_dict = torch.load('safety_classifier_model.pth', map_location='cpu')# Remove 'module.' prefix from keys (caused by DataParallel training)new_state_dict = {}for key, value in state_dict.items():if key.startswith('module.'):new_key = key[7:] # Remove 'module.' prefixelse:new_key = keynew_state_dict[new_key] = valuemodel.load_state_dict(new_state_dict)model.eval()tokenizer = AutoTokenizer.from_pretrained('./tokenizer')# Create Gradio interfaceiface = gr.Interface(fn=predict_safety,
app.py+14-2