From d6481579f6e114dfaae25364efd3647e7eb067a6 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Thu, 8 Feb 2024 22:17:33 +0530 Subject: [PATCH] show custom urls in uppy rename Custom URLs -> Submit Links in Bulk --- daras_ai_v2/bot_integration_widgets.py | 3 +++ daras_ai_v2/doc_search_settings_widgets.py | 8 +++----- gooey_ui/components/__init__.py | 4 +--- recipes/QRCodeGenerator.py | 17 +++-------------- routers/root.py | 6 ++++++ 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/daras_ai_v2/bot_integration_widgets.py b/daras_ai_v2/bot_integration_widgets.py index 0790f0b43..73c6ccad0 100644 --- a/daras_ai_v2/bot_integration_widgets.py +++ b/daras_ai_v2/bot_integration_widgets.py @@ -19,6 +19,9 @@ def general_integration_settings(bi: BotIntegration): st.session_state[f"_bi_user_language_{bi.id}"] = BotIntegration._meta.get_field( "user_language" ).default + st.session_state[f"_bi_streaming_enabled_{bi.id}"] = ( + BotIntegration._meta.get_field("streaming_enabled").default + ) st.session_state[f"_bi_show_feedback_buttons_{bi.id}"] = ( BotIntegration._meta.get_field("show_feedback_buttons").default ) diff --git a/daras_ai_v2/doc_search_settings_widgets.py b/daras_ai_v2/doc_search_settings_widgets.py index f175cd911..a64572b99 100644 --- a/daras_ai_v2/doc_search_settings_widgets.py +++ b/daras_ai_v2/doc_search_settings_widgets.py @@ -40,11 +40,8 @@ def document_uploader( documents = st.session_state.get(key) or [] if isinstance(documents, str): documents = [documents] - has_custom_urls = not all(map(is_user_uploaded_url, documents)) custom_key = "__custom_" + key - if st.checkbox( - "Enter Custom URLs", key=f"__custom_checkbox_{key}", value=has_custom_urls - ): + if st.session_state.get(f"__custom_checkbox_{key}"): if not custom_key in st.session_state: st.session_state[custom_key] = "\n".join(documents) if accept_multiple_files: @@ -67,7 +64,7 @@ def document_uploader( **kwargs, ) if accept_multiple_files: - st.session_state[key] = text_value.strip().splitlines() + st.session_state[key] = filter(None, text_value.strip().splitlines()) else: st.session_state[key] = text_value else: @@ -79,6 +76,7 @@ def document_uploader( accept=accept, accept_multiple_files=accept_multiple_files, ) + st.checkbox("Submit Links in Bulk", key=f"__custom_checkbox_{key}") documents = st.session_state.get(key, []) try: documents = list(_expand_gdrive_folders(documents)) diff --git a/gooey_ui/components/__init__.py b/gooey_ui/components/__init__.py index 408b950fb..0814d65e9 100644 --- a/gooey_ui/components/__init__.py +++ b/gooey_ui/components/__init__.py @@ -293,9 +293,7 @@ def text_area( # assert not value, "only one of value or key can be provided" # else: if not key: - key = md5_values( - "textarea", label, height, help, value, placeholder, label_visibility - ) + key = md5_values("textarea", label, height, help, placeholder, label_visibility) value = str(state.session_state.setdefault(key, value) or "") if label_visibility != "visible": label = None diff --git a/recipes/QRCodeGenerator.py b/recipes/QRCodeGenerator.py index 34b615225..741149afd 100644 --- a/recipes/QRCodeGenerator.py +++ b/recipes/QRCodeGenerator.py @@ -566,20 +566,9 @@ def vcard_form(*, key: str) -> VCARD: st.error("No contact info found for that email") else: vcard = imported_vcard - # clear inputs - st.js( - # language=js - """ - const form = document.getElementById("gooey-form"); - if (!form) return; - Object.entries(fields).forEach(([k, v]) => { - const field = form["__vcard_data__" + k]; - if (!field) return; - field.value = v; - }); - """, - fields=vcard.dict(), - ) + # update inputs + for k, v in vcard.dict().items(): + st.session_state[f"__vcard_data__{k}"] = v vcard.format_name = st.text_input( "Name*", diff --git a/routers/root.py b/routers/root.py index 6f854ba20..e5f27edc6 100644 --- a/routers/root.py +++ b/routers/root.py @@ -31,6 +31,7 @@ RedirectException, get_example_request_body, ) +from daras_ai_v2.bots import request_json from daras_ai_v2.copy_to_clipboard_button_widget import copy_to_clipboard_scripts from daras_ai_v2.db import FIREBASE_SESSION_COOKIE from daras_ai_v2.manage_api_keys_widget import manage_api_keys @@ -165,6 +166,11 @@ async def logout(request: Request): return RedirectResponse(request.query_params.get("next", DEFAULT_LOGOUT_REDIRECT)) +@app.post("/__/file-upload/url/meta") +async def file_upload(request: Request, body_json: dict = Depends(request_json)): + return dict(name=(body_json["url"]), type="url/undefined", size=None) + + @app.post("/__/file-upload/") def file_upload(request: Request, form_data: FormData = Depends(request_form_files)): from wand.image import Image