Skip to content

Commit

Permalink
fix: attachments.file_card supports url strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Col0ring committed Feb 21, 2025
1 parent 1546c2d commit f43b9dc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/tiny-lemons-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modelscope-studio/antdx': patch
'modelscope_studio': patch
---

fix: `attachments.file_card` supports url strings
2 changes: 1 addition & 1 deletion docs/components/antdx/suggestion/demos/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def select_suggestion(e: gr.EventData):
with ms.Application():
with antdx.XProvider():
antd.Typography.Paragraph(
"Set `block` to display in a whole row. ``extra` can be used to configure additional information."
"Set `block` to display in a whole row. `extra` can be used to configure additional information."
)
with antdx.Suggestion(
items=items,
Expand Down
39 changes: 37 additions & 2 deletions docs/layout_templates/chatbot/demos/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

model = "Qwen/Qwen2.5-VL-72B-Instruct"

save_history = False

# =========== Configuration

DEFAULT_PROMPTS = [{
Expand Down Expand Up @@ -111,7 +113,8 @@ def format_history(history):
}] + [{
"type": "image_url",
"image_url": image_to_base64(file["path"])
} for file in item["content"]["files"]]
} for file in item["content"]["files"]
if os.path.exists(file["path"])]
})
elif item["role"] == "assistant":
messages.append(item)
Expand Down Expand Up @@ -400,6 +403,22 @@ def paste_file(attachments_value, state_value, e: gr.EventData):
e._data["payload"][0]), gr.update(
open=True), gr.update(value=state_value)

@staticmethod
def update_browser_state(state_value):

return gr.update(value=dict(
conversations=state_value["conversations"],
conversations_history=state_value["conversations_history"]))

@staticmethod
def apply_browser_state(browser_state_value, state_value):
state_value["conversations"] = browser_state_value["conversations"]
state_value["conversations_history"] = browser_state_value[
"conversations_history"]
return gr.update(
items=browser_state_value["conversations"]), gr.update(
value=state_value)


css = """
#chatbot {
Expand Down Expand Up @@ -464,13 +483,14 @@ def logo():
ms.Span("Chatbot")


with gr.Blocks(css=css) as demo:
with gr.Blocks(css=css, fill_width=True) as demo:
state = gr.State({
"conversations_history": {},
"conversations": [],
"conversation_id": "",
"attachments_open": False,
})

with ms.Application(), antdx.XProvider(
theme=DEFAULT_THEME, locale=DEFAULT_LOCALE), ms.AutoLoading():
with antd.Row(gutter=[20, 20], wrap=False, elem_id="chatbot"):
Expand Down Expand Up @@ -841,6 +861,21 @@ def logo():
"CloudUploadOutlined")

# Events Handler
if save_history:
browser_state = gr.BrowserState(
{
"conversations_history": {},
"conversations": [],
},
storage_key="ms_chatbot_storage")
state.change(fn=Gradio_Events.update_browser_state,
inputs=[state],
outputs=[browser_state])

demo.load(fn=Gradio_Events.apply_browser_state,
inputs=[browser_state, state],
outputs=[conversations, state])

add_conversation_btn.click(fn=Gradio_Events.new_chat,
inputs=[state],
outputs=[conversations, chatbot, state])
Expand Down
2 changes: 2 additions & 0 deletions docs/layout_templates/coder_artifacts/demos/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def clear_history(e: gr.EventData, state_value):
with antd.Flex(gap="small", wrap=True):
for example in EXAMPLES:
with antd.Card(
elem_style=dict(
flex="1 1 fit-content"),
hoverable=True) as example_card:
antd.Card.Meta(
title=example['title'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const AttachmentsFileCard = sveltify<
}
if (typeof item === 'string') {
return {
url: get_fetchable_url_or_file(item, urlRoot, urlProxyUrl),
url: item.startsWith('http')
? item
: get_fetchable_url_or_file(item, urlRoot, urlProxyUrl),
uid: item,
name: item.split('/').pop(),
};
Expand Down

0 comments on commit f43b9dc

Please sign in to comment.