Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
first attempt at button push
Browse files Browse the repository at this point in the history
  • Loading branch information
reisner committed Jun 29, 2023
1 parent e498b14 commit 5099094
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 3 deletions.
22 changes: 21 additions & 1 deletion dashboard_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ index_to_alias_mapping <- function(es, alias_names) {

if (!all(is.na(mapping_df$aliases))) {
mapping_df = mapping_df %>%
tidyr::unnest_longer(aliases, indices_to = "alias_name") %>%
tidyr::unnest_longer(aliases, indices_to = "alias_name", keep_empty = TRUE) %>%
select(-aliases) %>%
mutate(alias_name = dplyr::coalesce(alias_name, index_name)) # use index name if alias name not present
} else {
# None of the specified datasets had an alias, so the column doesnt exist:
mapping_df$alias_name = mapping_df$index_name
}

# browser()
assertthat::assert_that(all(alias_names %in% union(mapping_df$alias_name, mapping_df$index_name)), msg = "some requested aliases/indices are not in Elastic Search")

mapping_df <- mapping_df %>%
Expand Down Expand Up @@ -378,6 +379,25 @@ query_text_depot <- function(query_info = NULL,
results
}

get_document_summary <- function(query,
api_url,
api_user,
api_password,
api_version) {
# cleaned_query = URLencode(query)
body = list(query = query)
response = api_url %>%
paste0("/embeddings_api/", api_version, "/summarize") %>%
httr::POST(authenticate(api_user, api_password), body = body, encode = "json")

if (response$status != 200) {
stop(paste0("ERROR From API at ", api_url, " with user ", api_user, " in get_embedding_vector(): ", as.character(response)))
}

content = httr::content(response)
content$summary
}

get_embedding_vector <- function(query,
api_url,
api_user,
Expand Down
99 changes: 97 additions & 2 deletions search_results_table_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,13 @@ searchResultsTable <- function(input, output, session,
str_replace_all("\n", "<br />") %>%
HTML()

shinyWidgets::sendSweetAlert(
# shinyWidgets::sendSweetAlert(
shinyWidgets::confirmSweetAlert(
session = session,
inputId = session$ns("doc_info"),
title = "Matching Document Information",
type = "", # no icon
btn_labels = "OK",
text = tagList(
strong(sprintf('Query: "%s"', query_info()$query),
style = "font-size: 14px; padding: 5px"),
Expand Down Expand Up @@ -260,11 +264,102 @@ searchResultsTable <- function(input, output, session,
",
display_text
)
)
),
# Only turn on summaries if we've specified an API Host,
# and this is a long piece of text:

# ifelse(!is.null(get_configs()$embedding_api_host) & (row$num_chars > 1000),
if (!is.null(get_configs()$embedding_api_host) & (row$num_chars > 1000)) {
actionButton(session$ns("summary_button"), "Summarize Text")
} else {
""
},
# actionButton(session$ns("summary_button"), "Summarize Text"),
uiOutput(session$ns("summary_section")), # %>% shinycssloaders::withSpinner()


# conditionalPanel(
# condition = "input.search_results_table-summary_button",
# "BLAHBLAH"
# )


# actionButton("summary_button", "Push Me!"),
# shinyBS::bsCollapse(id = "collapseExample", open = "Panel 1",
# shinyBS::bsCollapsePanel("Panel 1", "This is a panel with just text ",
# "and has the default style. You can change the style in ",
# "the sidebar.", style = "info"))
),
width = 1000,
html = TRUE
)

observeEvent(input$doc_info, {
print("CLOSED DIALOG!")
output$summary_section = renderText({""})#NULL
# shinyjs::show("summary_button")
# shinyjs::hide("summary_section")
})

output$summary_section = renderText({""})#NULL

observe({
req(input$summary_button)
if (input$summary_button == 0)
return()
isolate({
print("BUTTON PUSHED")
print(input$summary_button)
shinycssloaders::showPageSpinner()
# shinyjs::show("summary_section")
configs = get_configs()
summary = substr(doc$text, 1, 10)
# summary = get_document_summary(doc$text,
# configs$embedding_api_host,
# configs$embedding_api_user,
# configs$embedding_api_password,
# configs$embedding_api_version)
# print(summary)
output$summary_section = renderUI({
print("RENDERING SUMMARY")
tagList(
strong("AI-generated Text Summary"),
br(),
summary
)
})
shinycssloaders::hidePageSpinner()
print("DONE BUTTON PUSH")
})
})

# observeEvent(input$summary_button, {
# shinycssloaders::showPageSpinner()
# shinyjs::show("summary_section")
# configs = get_configs()
# print("BUTTON PUSHED")
# summary = "Summary Here"
# summary = get_document_summary(doc$text,
# configs$embedding_api_host,
# configs$embedding_api_user,
# configs$embedding_api_password,
# configs$embedding_api_version)
# print(summary)
# output$summary_section = renderUI({
# print("IN RENDER")
# tagList(
# strong("AI-generated Text Summary"),
# br(),
# summary
# )
# })
# shinycssloaders::hidePageSpinner()
# print("DONE HERE")
# })

# observeEvent(input$summary_button, ({
# shinyBS::updateCollapse(session, "collapseExample", open = "Panel 1")
# }))
})

}

0 comments on commit 5099094

Please sign in to comment.