赞
踩
Pip install streamlit
文档:
https://docs.streamlit.io/develop/api-reference/widgets/st.color_picker
import streamlit as st # 标题 st.title("日志分析工具") # 创建选项卡 tab1, tab2 = st.tabs(["去重功能", "检索功能"]) with tab1: st.header("去重功能") log_file = st.file_uploader("上传日志文件", type=["txt", "log"]) threshold = st.slider("相似度调整", 0.0, 1.0, step=0.01, value=0.8) remove_button = st.button("去重") if remove_button and log_file is not None: remove_output, unique_file_content, analogous_file_content = remove_and_print_analogous_logs(log_file, threshold) st.session_state['remove_output'] = remove_output st.session_state['unique_file_content'] = unique_file_content st.session_state['analogous_file_content'] = analogous_file_content if 'remove_output' in st.session_state: st.text_area("相似日志输出", st.session_state['remove_output'], height=300) st.download_button("下载去重后的日志", st.session_state['unique_file_content'], file_name="unique_logs.txt") st.download_button("下载相似日志", st.session_state['analogous_file_content'], file_name="analogous_logs.txt") with tab2: st.header("检索功能") log_file_search = st.file_uploader("上传日志文件", type=["txt", "log"], key="log_file_search") search_log = st.text_input("输入要检索的日志") threshold_search = st.slider("相似度调整", 0.0, 1.0, step=0.01, value=0.8, key="threshold_search") search_button = st.button("检索", key="search_button") if search_button and log_file_search is not None: search_output = search_similar_logs(log_file_search, search_log, threshold_search) st.session_state['search_output'] = search_output if 'search_output' in st.session_state: st.text_area("检索相似日志输出", st.session_state['search_output'], height=300)
streamlit run demo.py
第一次运行的时候报错出现:
OSError: [Errno 28] inotify watch limit reached 是由于 Linux 系统的 inotify 监视器数量达到上限导致的。可以通过增加 inotify 监视器的数量来解决这个问题。
解决方法
在终端中执行以下命令来临时增加 inotify 监视器的数量:
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p
编辑 /etc/sysctl.conf 文件:
sudo nano /etc/sysctl.conf
#在文件末尾添加以下一行:
fs.inotify.max_user_watches=524288
#保存并退出编辑器,然后运行以下命令使更改生效:
sudo sysctl -p
pip install gradio
import gradio as gr # 使用 Gradio 创建界面 with gr.Blocks() as demo: gr.Markdown("## 日志分析工具") with gr.Tab("去重功能"): log_file = gr.File(label="上传日志文件") threshold = gr.Slider(0.0, 1.0, step=0.01, value=0.8, label="相似度调整") remove_button = gr.Button("去重") remove_output = gr.Textbox(label="相似日志输出") unique_file_output = gr.File(label="下载去重后的日志") analogous_file_output = gr.File(label="下载相似日志") remove_button.click(fn=remove_and_print_analogous_logs, inputs=[log_file, threshold], outputs=[remove_output, unique_file_output, analogous_file_output]) with gr.Tab("检索功能"): log_file_search = gr.File(label="上传日志文件") search_log = gr.Textbox(label="输入要检索的日志") threshold_search = gr.Slider(0.0, 1.0, step=0.01, value=0.8, label="相似度调整") search_button = gr.Button("检索") search_output = gr.Textbox(label="检索相似日志输出") search_button.click(fn=search_similar_logs, inputs=[log_file_search, search_log, threshold_search], outputs=search_output) demo.launch(server_name="0.0.0.0", server_port=7005)
聊天框模式
# 创建 Gradio 界面 def create_gradio_interface(): with gr.Blocks(css=custom_css) as demo: gr.Markdown("## 日志知识库") with gr.Tab("知识库查询功能"): chatbot = gr.Chatbot(label="聊天框",height=550,bubble_full_width=False) user_input = gr.Textbox(label="输入查询", placeholder="输入你的查询") send_button = gr.Button("发送") clear = gr.ClearButton([user_input, chatbot]) examples = gr.Examples( examples=["R5版本升级失败", "网络中断","CPU高而且防火墙无法登陆","接口出现反复down和up的情况"], inputs=user_input ) send_button.click(search_with_query, inputs=[chatbot, user_input], outputs=chatbot) # 上传部分 with gr.Tab("添加知识功能"): fault_type = gr.Textbox(label="故障类型", placeholder="输入故障类型") fault_description = gr.Textbox(label="故障描述", placeholder="输入故障描述") operation_mode = gr.Textbox(label="工作模式", placeholder="输入工作模式") component = gr.Textbox(label="组件", placeholder="输入组件") root_cause = gr.Textbox(label="问题根源", placeholder="输入问题根源") final_solution = gr.Textbox(label="最终解决方案", placeholder="输入最终解决方案") upload_button = gr.Button("上传") upload_output = gr.Textbox(label="上传结果") # 绑定按钮和函数 upload_button.click(upload_with_qa, inputs=[fault_type,fault_description,operation_mode,component,root_cause,final_solution], outputs=upload_output) # 设置界面的标题和描述 demo.title = "知识库交互界面" demo.description = "这个界面允许你搜索和上传知识库内容" return demo
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。