Update app.py
Browse files123import gradio as grgr.load("models/google-bert/bert-base-uncased").launch()123456789101112131415161718192021222324252627282930313233import gradio as grimport torchfrom transformers import BertTokenizer, BertModeltokenizer = BertTokenizer.from_pretrained('google/bert-base-uncased')model = BertModel.from_pretrained('google/bert-base-uncased')def predict(input_text):# Tokenize the input textinputs = tokenizer.encode_plus(input_text,add_special_tokens=True,max_length=512,return_attention_mask=True,return_tensors='pt')# Run the input through the BERT modeloutputs = model(inputs['input_ids'], attention_mask=inputs['attention_mask'])last_hidden_state = outputs.last_hidden_state[:, 0, :]# Return the output (e.g., the pooled output)return last_hidden_state.detach().numpy()# Create the Gradio appapp = gr.Interface(fn=predict,inputs="text",outputs="numpy",title="BERT App",description="Enter some text to see the BERT output")
app.py+31-1