|
import numpy as np |
|
from sentence_transformers import SentenceTransformer |
|
from sklearn.metrics.pairwise import cosine_similarity |
|
from shiny import App, render, ui |
|
import pandas as pd |
|
|
|
|
|
|
|
|
|
|
|
|
|
model = SentenceTransformer('all-MiniLM-L6-v2') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queries = pd.read_excel("egu_session_descriptions.xlsx").Description |
|
titles = pd.read_excel("egu_session_descriptions.xlsx").Title |
|
ids = pd.read_excel("egu_session_descriptions.xlsx").ID |
|
ids = [int(num) for num in ids] |
|
|
|
prefix = "https://meetingorganizer.copernicus.org/EGU25/session/" |
|
|
|
|
|
urls = [f"{prefix}{num}" for num in ids] |
|
|
|
|
|
|
|
|
|
query_embeddings = model.encode(queries) |
|
|
|
|
|
|
|
app_ui = ui.page_fluid( |
|
ui.h3("EGU25 AI-session recommender"), |
|
|
|
ui.card( |
|
ui.card_header("How to use"), |
|
ui.p("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lore.")), |
|
|
|
|
|
ui.input_text_area("user_input", "Enter your text:", placeholder="Paste abstract", width = "100%"), |
|
ui.input_action_button("submit", "Get session recommendations", class_="btn btn-primary"), |
|
ui.HTML("<hr>"), |
|
ui.output_ui("results"), |
|
ui.card_footer("Application developed by Jan Sodoge. Project by the Computational Extreme Events Group at the Helmholtz-Centre For Environmental Research"), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
def server(input, output, session): |
|
@output |
|
@render.ui |
|
def results(): |
|
if input.submit(): |
|
user_text = input.user_input() |
|
if user_text: |
|
|
|
user_embedding = model.encode([user_text]) |
|
|
|
|
|
similarities = cosine_similarity(user_embedding, query_embeddings).flatten() |
|
|
|
|
|
top_indices = np.argsort(similarities)[-5:][::-1] |
|
|
|
|
|
result_boxes = [ |
|
ui.a( |
|
ui.div( |
|
titles[idx], |
|
style="padding: 10px; margin: 5px; border-radius: 5px; color: white; font-weight: bold; background-color: #4682B4;" |
|
), |
|
href=urls[idx], target="_blank" |
|
) |
|
for idx in top_indices |
|
] |
|
|
|
return result_boxes |
|
return ui.div("Please enter text and press the button.") |
|
|
|
|
|
app = App(app_ui, server) |
|
|
|
if __name__ == "__main__": |
|
app.run() |
|
|