Spaces:
Sleeping
Sleeping
File size: 2,714 Bytes
b68dc3f 225fe85 b68dc3f 225fe85 b68dc3f 225fe85 b68dc3f 225fe85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
import gradio as gr
import json
from dialogue_management import manage_dialogue
from function_trigger import trigger_function
from config import load_config
from skill_repository import load_skills, save_skills, add_skill, delete_skill
config = load_config()
skills = load_skills()
# 对话功能
def respond(user_input):
response, action = manage_dialogue(user_input, skills)
result = trigger_function(action, config)
return response, result
# 显示指令库文件
def show_skills():
with open('skills.json', 'r', encoding='utf-8') as file:
skills_data = json.load(file)
return json.dumps(skills_data, ensure_ascii=False, indent=4)
# 添加新的技能
def add_new_skill(triggers, action):
trigger_list = [trigger.strip() for trigger in triggers.split(',')]
new_skill = {
"triggers": trigger_list,
"action": action
}
add_skill(new_skill)
return show_skills()
# 删除技能
def remove_skill(action):
delete_skill(action)
return show_skills()
with gr.Blocks() as demo:
with gr.Tab("AI Assistant Response"):
skills = load_skills()
gr.Markdown("## AI Assistant Response")
user_input = gr.Textbox(label="User Input")
ai_response = gr.Markdown()
action_result = gr.Textbox(label="Action Result")
respond_button = gr.Button("Respond")
respond_button.click(
respond,
inputs=user_input,
outputs=[ai_response, action_result]
)
with gr.Tab("View Skills Library"):
gr.Markdown("## Skills Library")
skills_output = gr.Code(label="Skills Library")
load_skills_button = gr.Button("Load Skills")
load_skills_button.click(
show_skills,
outputs=skills_output
)
with gr.Tab("Add Skill"):
gr.Markdown("## Add Skill")
new_triggers = gr.Textbox(label="Triggers (comma separated)")
new_action = gr.Textbox(label="Action")
add_skill_output = gr.Code(label="Updated Skills Library")
add_skill_button = gr.Button("Add Skill")
add_skill_button.click(
add_new_skill,
inputs=[new_triggers, new_action],
outputs=add_skill_output
)
with gr.Tab("Delete Skill"):
gr.Markdown("## Delete Skill")
delete_action = gr.Textbox(label="Action to Delete")
delete_skill_output = gr.Code(label="Updated Skills Library")
delete_skill_button = gr.Button("Delete Skill")
delete_skill_button.click(
remove_skill,
inputs=delete_action,
outputs=delete_skill_output
)
if __name__ == "__main__":
demo.launch()
|