Skip to content

Commit

Permalink
feat: support publish btn
Browse files Browse the repository at this point in the history
  • Loading branch information
nil.wyw committed Nov 27, 2023
1 parent 80364fe commit e31f68d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
21 changes: 14 additions & 7 deletions apps/agentfabric/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from config_utils import (Config, get_avatar_image, get_user_cfg_file,
get_user_dir, parse_configuration, save_avatar_image,
save_builder_configuration)
from gradio_utils import ChatBot, format_cover_html
from gradio_utils import ChatBot, format_cover_html, format_goto_publish_html
from publish_util import prepare_agent_zip
from user_core import init_user_chatbot_agent

Expand Down Expand Up @@ -261,8 +261,14 @@ def process_configuration(uuid_str, bot_avatar, name, description,
lambda evt: evt[0],
inputs=[user_chat_bot_suggest],
outputs=[preview_chat_input])
publish_button = gr.Button('Publish')
output_url = gr.Textbox(label='Agent url for you', disabled=True)
with gr.Accordion(label="发布", open=False):
with gr.Row():
with gr.Column():
gr.Markdown("### 1.点击 Build 完成构建")
publish_button = gr.Button('Build')
with gr.Column():
gr.Markdown("### 2.点击 Publish 跳转创空间完成 Agent 发布")
publish_link = gr.HTML(value=format_goto_publish_html("", True))

configure_updated_outputs = [
state,
Expand Down Expand Up @@ -420,15 +426,16 @@ def preview_send_message(chatbot, input, _state):
outputs=[user_chatbot, user_chat_bot_cover, preview_chat_input])

# configuration for publish
def publish_agent(output_url, name, uuid_str, state):
def publish_agent(name, uuid_str, state):
uuid_str = check_uuid(uuid_str)
output_url = prepare_agent_zip(name, uuid_str, state)
return output_url
# output_url = "https://test.url"
return format_goto_publish_html(output_url)

publish_button.click(
publish_agent,
inputs=[output_url, name_input, uuid_str, state],
outputs=[output_url],
inputs=[name_input, uuid_str, state],
outputs=[publish_link],
)

demo.load(
Expand Down
20 changes: 20 additions & 0 deletions apps/agentfabric/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@
color: #ddd;
}

.publish_link_container > a {
display: block;
border-radius: var(--button-large-radius);
padding: var(--button-large-padding);
font-weight: var(--button-large-text-weight);
font-size: var(--button-large-text-size);
border: var(--button-border-width) solid var(--button-secondary-border-color);
background: var(--button-secondary-background-fill);
color: var(--button-secondary-text-color) !important;
cursor: pointer;
text-decoration: none !important;
text-align: center;
}

.publish_link_container > .disabled {
cursor: not-allowed;
opacity: .5;
filter: grayscale(30%);
}

.markdown-body .message {
white-space: pre-wrap;
}
Expand Down
21 changes: 21 additions & 0 deletions apps/agentfabric/gradio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re

import json
from urllib import parse
import markdown
from gradio.components import Chatbot as ChatBotBase
from modelscope_agent.output_parser import MRKLOutputParser
Expand Down Expand Up @@ -44,6 +45,26 @@ def format_cover_html(configuration, bot_avatar_path):
</div>
"""

def format_goto_publish_html(zip_url, disable = False):
if disable:
return f"""
<div class="publish_link_container">
<a class="disabled">Publish</a>
</div>
"""
else:
params = {
"AGENT_URL": zip_url
}
template = "modelscope/agent_template"
params_str = json.dumps(params)
link_url = f"https://www.modelscope.cn/studios/fork?target={template}&overwriteEnv={parse.quote(params_str)}"
return f"""
<div class="publish_link_container">
<a href="{link_url}" target="_blank">Publish</a>
</div>
"""


class ChatBot(ChatBotBase):

Expand Down

0 comments on commit e31f68d

Please sign in to comment.