Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
neoguojing committed Aug 31, 2024
1 parent a394300 commit 92f88fe
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 59 deletions.
41 changes: 31 additions & 10 deletions detectron/demo/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from retriever import knowledgeBase
from yolo_predictor import YOLOPredictor
from ocr import do_ocr
import llm
params = {
"algo_type": None,
"input_image":None
Expand Down Expand Up @@ -137,8 +138,12 @@ def create_event_handlers():
# db_select_handler, gradio('db_select'), None, show_progress=False
# )

components['llm_client'].change(
do_llm_change, gradio('llm_client'), gradio('ak','sk','llm_setting_btn')
)

components['llm_setting_btn'].click(
llm, gradio('ak','sk','llm_client'), None
llm_setup, gradio('ak','sk','llm_client'), gradio('ak','sk','llm_setting_btn')
)

def do_refernce(algo_type,input_image):
Expand Down Expand Up @@ -354,11 +359,23 @@ def do_llm_response(history,selected_dbs):

history[-1][1] += quote

llm_client = None
def llm(ak,sk,client):
global llm_client
llm_client = llm.openai_client
def llm_setup(ak,sk,client):
import llm
llm.init_param(ak,sk)
if ak == "" and sk == "":
gr.Info("重置成功")
else:
gr.Info("设置成功")

components["ak"] = gr.Textbox(label="appid",visible=False)
components["sk"] = gr.Textbox(label="secret",visible=False)
components["llm_setting_btn"] = gr.Button(value="设置",visible=False)
return components["ak"],components["sk"],components["llm_setting_btn"]

def do_llm_change(client):
global llm_client

if client == "Wenxin":
llm_client = llm.baidu_client
elif client == "Tongyi":
Expand All @@ -367,14 +384,18 @@ def llm(ak,sk,client):
llm_client = llm.hg_client
elif client == "llama3.1":
llm_client = llm.openai_client

print("------------",llm_client)
if ak == "" and sk == "":
gr.Info("重置成功")
else:
gr.Info("设置成功")

return llm_client
if client != "llama3.1":
components["ak"] = gr.Textbox(label="appid",visible=True)
components["sk"] = gr.Textbox(label="secret",visible=True)
components["llm_setting_btn"] = gr.Button(value="设置",visible=True)
else:
components["ak"] = gr.Textbox(label="appid",visible=False)
components["sk"] = gr.Textbox(label="secret",visible=False)
components["llm_setting_btn"] = gr.Button(value="设置",visible=False)

return components["ak"],components["sk"],components["llm_setting_btn"]

def file_handler(file_objs,name):
import shutil
Expand Down
7 changes: 5 additions & 2 deletions detectron/demo/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def query(payload):


chat =ChatOpenAI(
model="llama3.1",
# model="llama3.1",
model="qwen2",
# model="phi3.5:3.8b-mini-instruct-fp16",
# model="llama3.1-local",
openai_api_key="121212",
base_url="http://192.168.1.7:11434/v1/",
)
Expand All @@ -110,7 +113,7 @@ def query(payload):
[
(
"system",
"You are a helpful assistant. Answer all questions to the best of your ability.",
"You are a helpful assistant. Answer all questions to the best of your ability.Please use simple chinese as default language.",
),
MessagesPlaceholder(variable_name="chat_history"),
("human", "{input}"),
Expand Down
95 changes: 48 additions & 47 deletions detectron/demo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,54 @@

def create_ui():
with gr.Blocks() as demo:
with gr.Tab("问答"):
with gr.Row():
with gr.Column(scale=1):
with gr.Group():
components["llm_client"] =gr.Dropdown(["llama3.1", "Wenxin", "Tongyi","Huggingface"],value="llama3.1", label="请选择大语言模型")
components["ak"] = gr.Textbox(label="appid",visible=False)
components["sk"] = gr.Textbox(label="secret",visible=False)
components["llm_setting_btn"] = gr.Button(value="设置",visible=False)
components["db_select"] = gr.CheckboxGroup(knowledgeBase.get_bases(),label="知识库", info="可选择1个或多个知识库")
with gr.Column(scale=3):
with gr.Group():
components["chatbot"] = gr.Chatbot(
[(None,"你好,有什么需要帮助的?")],
elem_id="chatbot",
bubble_full_width=False,
height=600
)
components["chat_input"] = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)

with gr.Tab("知识库"):
with gr.Row():
with gr.Column(scale=1):
with gr.Group():
components["db_view"] = gr.Dataframe(
headers=["列表"],
datatype=["str"],
row_count=2,
col_count=(1, "fixed"),
interactive=False
)
with gr.Column(scale=2):
with gr.Row():
with gr.Column(scale=2):
components["db_name"] = gr.Textbox(label="名称", info="请输入库名称", lines=1, value="")
with gr.Column(scale=2):
components["db_submit_btn"] = gr.Button(value="提交")
components["file_upload"] = gr.File(elem_id='file_upload',file_count='multiple',label='文档上传', file_types=[".pdf", ".doc", '.docx', '.json', '.csv'])
with gr.Row():
with gr.Column(scale=2):
components["db_input"] = gr.Textbox(label="关键词", lines=1, value="")
with gr.Column(scale=1):
components["db_test_select"] = gr.Dropdown(knowledgeBase.get_bases(),multiselect=True, label="知识库选择")
with gr.Column(scale=1):
components["dbtest_submit_btn"] = gr.Button(value="检索")
with gr.Row():
with gr.Group():
components["db_search_result"] = gr.JSON(label="检索结果")

with gr.Tab("基础算法"):
with gr.Row():
with gr.Column(scale=2):
Expand Down Expand Up @@ -211,53 +259,6 @@ def create_ui():
components["sam_output"] = gr.Gallery(elem_id='sam_output',label='输出',columns=1,interactive=False)
components["sam_video_output"] = gr.PlayableVideo(label='输出',visible=False,width=width,height=height)

with gr.Tab("知识库"):
with gr.Row():
with gr.Column(scale=1):
with gr.Group():
components["db_view"] = gr.Dataframe(
headers=["列表"],
datatype=["str"],
row_count=2,
col_count=(1, "fixed"),
interactive=False
)
with gr.Column(scale=2):
with gr.Row():
with gr.Column(scale=2):
components["db_name"] = gr.Textbox(label="名称", info="请输入库名称", lines=1, value="")
with gr.Column(scale=2):
components["db_submit_btn"] = gr.Button(value="提交")
components["file_upload"] = gr.File(elem_id='file_upload',file_count='multiple',label='文档上传', file_types=[".pdf", ".doc", '.docx', '.json', '.csv'])
with gr.Row():
with gr.Column(scale=2):
components["db_input"] = gr.Textbox(label="关键词", lines=1, value="")
with gr.Column(scale=1):
components["db_test_select"] = gr.Dropdown(knowledgeBase.get_bases(),multiselect=True, label="知识库选择")
with gr.Column(scale=1):
components["dbtest_submit_btn"] = gr.Button(value="检索")
with gr.Row():
with gr.Group():
components["db_search_result"] = gr.JSON(label="检索结果")

with gr.Tab("问答"):
with gr.Row():
with gr.Column(scale=1):
with gr.Group():
components["ak"] = gr.Textbox(label="appid")
components["sk"] = gr.Textbox(label="secret")
components["llm_client"] =gr.Radio(["llama3.1", "Wenxin", "Tongyi","Huggingface"],value="Wenxin", label="llm")
components["llm_setting_btn"] = gr.Button(value="设置")
with gr.Column(scale=2):
with gr.Group():
components["chatbot"] = gr.Chatbot(
[(None,"你好,有什么需要帮助的?")],
elem_id="chatbot",
bubble_full_width=False,
height=600
)
components["chat_input"] = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)
components["db_select"] = gr.CheckboxGroup(knowledgeBase.get_bases(),label="知识库", info="可选择1个或多个知识库")

create_event_handlers()
demo.load(init,None,gradio("db_view","db_select","db_test_select"))
Expand Down

0 comments on commit 92f88fe

Please sign in to comment.