Spaces:
Configuration error
Configuration error
Update model.py
Browse files
model.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
import requests
|
| 3 |
from config import HUGGINGFACE_API_URL, HUGGINGFACE_API_KEY
|
| 4 |
|
|
|
|
| 5 |
def get_huggingface_prediction(input_data): #input_data'yı main.py ile entegre etmeliyim
|
| 6 |
headers = {
|
| 7 |
"Authorization": f"Bearer {HUGGINGFACE_API_KEY}"
|
|
@@ -12,3 +13,12 @@ def get_huggingface_prediction(input_data): #input_data'yı main.py ile entegre
|
|
| 12 |
|
| 13 |
response = requests.post(HUGGINGFACE_API_URL, headers=headers, json=payload)
|
| 14 |
return response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
from config import HUGGINGFACE_API_URL, HUGGINGFACE_API_KEY
|
| 4 |
|
| 5 |
+
|
| 6 |
def get_huggingface_prediction(input_data): #input_data'yı main.py ile entegre etmeliyim
|
| 7 |
headers = {
|
| 8 |
"Authorization": f"Bearer {HUGGINGFACE_API_KEY}"
|
|
|
|
| 13 |
|
| 14 |
response = requests.post(HUGGINGFACE_API_URL, headers=headers, json=payload)
|
| 15 |
return response.json()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def calculate_similarity(text1, text2):
|
| 20 |
+
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
| 21 |
+
embedding1 = model.encode(text1, convert_to_tensor=True)
|
| 22 |
+
embedding2 = model.encode(text2, convert_to_tensor=True)
|
| 23 |
+
similarity_score = util.pytorch_cos_sim(embedding1, embedding2)
|
| 24 |
+
return similarity_score.item()
|