Spaces:
Runtime error
Runtime error
File size: 1,050 Bytes
7ea324d 6650ff5 6ac529c 6650ff5 4ea6b57 b6aa4bf b358447 4ea6b57 6ac529c ef5a693 cdd39e8 4ea6b57 6ac529c 063e402 6650ff5 4ea6b57 3610f49 6ac529c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import gradio as gr
from transformers import pipeline
pipeline = pipeline("feature-extraction", model="WhereIsAI/UAE-Large-V1")
def predict(text):
text = text.lower()
text = text.translate(str.maketrans('', '', string.punctuation))
title_outputs = pipeline(text)
title_outputs = torch.tensor(title_outputs)
# Mean pooling
title_embedding = title_outputs.mean(dim=1)
#title_embedding = title_outputs.last_hidden_state.mean(dim=1)
term_outputs = pipeline('multivitamin for men')
term_outputs = torch.tensor(term_outputs)
term_embedding = term_outputs.mean(dim=1)
#term_embedding = term_outputs.last_hidden_state.mean(dim=1)
semantic_score = cosine_similarity(title_embedding.flatten(), term_embedding.flatten()) * 100
return title_embedding #str(format(semantic_score,'.2f'))
def predict1(text):
return(text)
gradio_app = gr.Interface(
predict,
inputs='text',
outputs='text',
title="Keyword Score",
)
if __name__ == "__main__":
gradio_app.launch() |