JariYP commited on
Commit
29d11e1
1 Parent(s): b2db1a9

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -31
app.py DELETED
@@ -1,31 +0,0 @@
1
- import streamlit as st
2
- from transformers import pipeline, AutoModel, AutoTokenizer
3
-
4
- # Load the model and tokenizer
5
- model_name = "sentence-transformers/all-MiniLM-L6-v2"
6
- model = AutoModel.from_pretrained(model_name)
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
-
9
- # Create a Streamlit app
10
- st.title("Sentence Similarity App")
11
-
12
- # Ask the user for input
13
- user_input = st.text_area("Enter a sentence:")
14
-
15
- # Define a function to calculate sentence similarity
16
- def calculate_similarity(input_text):
17
- similarity_pipeline = pipeline("feature-extraction", model=model, tokenizer=tokenizer)
18
- user_embedding = similarity_pipeline(input_text)[0]
19
- return user_embedding
20
-
21
- if user_input:
22
- # Calculate similarity with a reference sentence
23
- reference_sentence = "Hugging Face is an AI research organization."
24
- user_embedding = calculate_similarity(user_input)
25
- reference_embedding = calculate_similarity(reference_sentence)
26
-
27
- # Calculate cosine similarity
28
- similarity_score = round(float(user_embedding.dot(reference_embedding.T)), 4)
29
-
30
- # Display the similarity score
31
- st.write(f"Similarity Score with Reference Sentence: {similarity_score}")