Spaces:
Runtime error
Runtime error
File size: 1,538 Bytes
28be794 dd3c9f3 28be794 2ce35ec 28be794 dd3c9f3 28be794 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import streamlit as st
import time
import pandas as pd
import numpy as np
#pip install -U sentence-transformers
from sentence_transformers import SentenceTransformer, util
# Load document embeddings
doc_emb = np.loadtxt("abstract-embed.txt", dtype=float)
doc_emb
# Load data
df = pd.read_csv("sessions.csv", usecols=['Unique ID', 'Name', 'Description', 'Activity Code', 'Start Time', 'End Time', 'Location Name'])
df.head()
# Get attributes from dataframe
docs = list(df["Description"])
titles = list(df["Name"])
start_times = list(df["Start Time"])
end_times = list(df["End Time"])
locations = list(df["Location Name"])
# Query
query = input("Enter your query: ")
#Encode query and documents
query_emb = model.encode(query).astype(float)
#Compute dot score between query and all document embeddings
scores = util.dot_score(query_emb, doc_emb.astype(float))[0].cpu().tolist()
#Combine docs & scores with other attributes
doc_score_pairs = list(zip(docs, scores, titles, start_times, end_times, locations))
# top_k results to return
top_k=3
print(" Your top", top_k, "most similar sessions in the Summit:")
#Sort by decreasing score
doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
#Output presentation recommendations
for doc, score, title, start_time, end_time, location in doc_score_pairs[:top_k]:
print("Score: %f" %score)
print("Title: %s" %title)
print("Abstract: %s" %doc)
print("Location: %s" %location)
f"From {start_time} to {end_time}"
print('\n')
|