Change Liao
commited on
Commit
·
8eb6288
1
Parent(s):
2ef7320
修正統計資料內容
Browse files
app.py
CHANGED
@@ -323,6 +323,9 @@ def get_hr_files():
|
|
323 |
else:
|
324 |
return make_markdown_table(files)
|
325 |
|
|
|
|
|
|
|
326 |
def update_hr_km(files):
|
327 |
file_paths = [file.name for file in files]
|
328 |
dest_file_path=root_file_path+hr_source_path
|
@@ -336,6 +339,20 @@ def update_hr_km(files):
|
|
336 |
save_sqlite(sqlite_key, [Path(file_path).name for file_path in file_paths])
|
337 |
return get_hr_files()
|
338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
def clear_all_collection(collection_name):
|
340 |
pass
|
341 |
|
@@ -355,6 +372,9 @@ def clear_hr_datas():
|
|
355 |
delete_sql(sqlite_key)
|
356 |
return get_hr_files()
|
357 |
|
|
|
|
|
|
|
358 |
def num_of_collection(collection_name):
|
359 |
client = get_chroma_client(collection_name)
|
360 |
number = client.get_collection(collection_name).count()
|
@@ -558,7 +578,7 @@ def read_logs():
|
|
558 |
def pandas_analysis(prompt_str, message, chat_history):
|
559 |
dir_path = f"{root_file_path}{believe_source_path}/*.csv"
|
560 |
res = glob.glob(dir_path)
|
561 |
-
df = pd.concat(
|
562 |
local_deploy_id= "text-davinci-003"
|
563 |
local_model_name = "text-davinci-003"
|
564 |
llm = AzureOpenAI(
|
@@ -713,16 +733,10 @@ def gradio_run():
|
|
713 |
audio_html = gr.HTML(htm_audio, visible=False)
|
714 |
with gr.Column():
|
715 |
isAudio = gr.Checkbox(label="是否要有語音", info="要開啟語音嗎?查詢時間會增長")
|
716 |
-
|
717 |
-
### AI 虛擬客服:
|
718 |
-
* 這是一個實驗性質的AI 客服
|
719 |
-
* 講話超過15秒就不會產生,正在要求放寬限制
|
720 |
-
* 想要放誰的頭像都可以, 要放董事長也可以.
|
721 |
-
* 訂閱制(有效時間 6/13~7/13)
|
722 |
-
""")
|
723 |
|
724 |
with gr.Row():
|
725 |
-
chatbot = gr.Chatbot(value=[], elem_id="chatbot").style(height=
|
726 |
with gr.Row():
|
727 |
with gr.Column(scale=5):
|
728 |
msg = gr.Textbox(
|
@@ -770,14 +784,9 @@ def gradio_run():
|
|
770 |
建議先詢問欄位後, 後續再構思其他問題
|
771 |
""")
|
772 |
|
773 |
-
invField = gr.Textbox(visible=False)
|
774 |
-
dir_path = f"{root_file_path}{believe_source_path}/*.csv"
|
775 |
-
res = glob.glob(dir_path)
|
776 |
-
gr.Examples(res, label="資料庫檔案", inputs=invField, examples_per_page=4)
|
777 |
with gr.Row():
|
778 |
with gr.Column():
|
779 |
-
|
780 |
-
tmp_chatbot = gr.Chatbot(value=[], elem_id="tmp_chatbot").style(height=500)
|
781 |
with gr.Row():
|
782 |
with gr.Column(scale=5):
|
783 |
tmp_msg = gr.Textbox(show_label=False,placeholder="輸入你的問題",)
|
@@ -785,24 +794,27 @@ def gradio_run():
|
|
785 |
tmp_clear = gr.Button("清除對話")
|
786 |
with gr.Column():
|
787 |
prompt_textbox = gr.Textbox("""
|
788 |
-
|
789 |
有下列定義:
|
790 |
|
791 |
-
1.
|
792 |
|
793 |
請以中文回答我下面的問題:{message}
|
794 |
""", lines=10, label="Prompt:有{chat_history}及{message}, 請至少保留{message}變數",interactive=True, max_lines=10)
|
795 |
-
|
|
|
|
|
|
|
|
|
|
|
796 |
tmp_msg.submit(pandas_analysis, [prompt_textbox, tmp_msg, tmp_chatbot], [tmp_msg, tmp_chatbot],queue=True)
|
797 |
tmp_clear.click(lambda: None, None, tmp_chatbot, queue=False)
|
798 |
with gr.Row():
|
799 |
gr.Examples([
|
800 |
-
'你有什麼欄位?'
|
801 |
-
'資料裡有屬於台灣(TW)的員工有多少位?',
|
802 |
-
'全台灣的員工, 每人每天問五個問題, 1個月花費多少錢?',
|
803 |
-
'如果龍華廠區的員工每人每天問3個問題,台灣員工每人每天問7個問題, 請問這樣一個月多少錢?'
|
804 |
], label="訊息範例", inputs=tmp_msg)
|
805 |
-
|
|
|
806 |
demo.queue(concurrency_count=10)
|
807 |
lunch_style(demo,console)
|
808 |
|
|
|
323 |
else:
|
324 |
return make_markdown_table(files)
|
325 |
|
326 |
+
def get_be_csv_files():
|
327 |
+
return make_markdown_table(glob.glob(root_file_path+believe_source_path+"/*.csv"))
|
328 |
+
|
329 |
def update_hr_km(files):
|
330 |
file_paths = [file.name for file in files]
|
331 |
dest_file_path=root_file_path+hr_source_path
|
|
|
339 |
save_sqlite(sqlite_key, [Path(file_path).name for file_path in file_paths])
|
340 |
return get_hr_files()
|
341 |
|
342 |
+
def update_be_csv_km(files):
|
343 |
+
file_paths = [file.name for file in files]
|
344 |
+
dest_file_path=root_file_path+believe_source_path
|
345 |
+
if not os.path.exists(dest_file_path):
|
346 |
+
os.makedirs(dest_file_path)
|
347 |
+
|
348 |
+
for file in file_paths:
|
349 |
+
shutil.copy(file, dest_file_path)
|
350 |
+
|
351 |
+
if files == None:
|
352 |
+
return ''
|
353 |
+
else:
|
354 |
+
return make_markdown_table(files)
|
355 |
+
|
356 |
def clear_all_collection(collection_name):
|
357 |
pass
|
358 |
|
|
|
372 |
delete_sql(sqlite_key)
|
373 |
return get_hr_files()
|
374 |
|
375 |
+
def clear_be_csv_datas():
|
376 |
+
all_files_under_diretory(root_file_path+believe_source_path)
|
377 |
+
|
378 |
def num_of_collection(collection_name):
|
379 |
client = get_chroma_client(collection_name)
|
380 |
number = client.get_collection(collection_name).count()
|
|
|
578 |
def pandas_analysis(prompt_str, message, chat_history):
|
579 |
dir_path = f"{root_file_path}{believe_source_path}/*.csv"
|
580 |
res = glob.glob(dir_path)
|
581 |
+
df = pd.concat((pd.read_csv(f, encoding='unicode_escape') for f in res), ignore_index=True)
|
582 |
local_deploy_id= "text-davinci-003"
|
583 |
local_model_name = "text-davinci-003"
|
584 |
llm = AzureOpenAI(
|
|
|
733 |
audio_html = gr.HTML(htm_audio, visible=False)
|
734 |
with gr.Column():
|
735 |
isAudio = gr.Checkbox(label="是否要有語音", info="要開啟語音嗎?查詢時間會增長")
|
736 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
737 |
|
738 |
with gr.Row():
|
739 |
+
chatbot = gr.Chatbot(value=[], elem_id="chatbot").style(height=600)
|
740 |
with gr.Row():
|
741 |
with gr.Column(scale=5):
|
742 |
msg = gr.Textbox(
|
|
|
784 |
建議先詢問欄位後, 後續再構思其他問題
|
785 |
""")
|
786 |
|
|
|
|
|
|
|
|
|
787 |
with gr.Row():
|
788 |
with gr.Column():
|
789 |
+
tmp_chatbot = gr.Chatbot(value=[], elem_id="tmp_chatbot").style(height=700)
|
|
|
790 |
with gr.Row():
|
791 |
with gr.Column(scale=5):
|
792 |
tmp_msg = gr.Textbox(show_label=False,placeholder="輸入你的問題",)
|
|
|
794 |
tmp_clear = gr.Button("清除對話")
|
795 |
with gr.Column():
|
796 |
prompt_textbox = gr.Textbox("""
|
797 |
+
你是一位資料科學家,提供給你的資料是2023年每一週的click 次數.
|
798 |
有下列定義:
|
799 |
|
800 |
+
1. 欄位 23W01 代表2023年的第一個星期; 23W02 代表2023年的第二個星期
|
801 |
|
802 |
請以中文回答我下面的問題:{message}
|
803 |
""", lines=10, label="Prompt:有{chat_history}及{message}, 請至少保留{message}變數",interactive=True, max_lines=10)
|
804 |
+
be_csv_file_list=gr.Textbox(get_be_csv_files, label="CSV Files", placeholder="沒有任何檔案存在", max_lines=10, lines=10)
|
805 |
+
upload_button = gr.UploadButton("上傳統計資料(.csv格式)",file_types=[".csv"],file_count="multiple")
|
806 |
+
upload_button.upload(update_be_csv_km, inputs=upload_button, outputs=be_csv_file_list).then(get_be_csv_files,outputs=be_csv_file_list)
|
807 |
+
|
808 |
+
cleanDataBtn = gr.Button(value="刪除所有csv 資料")
|
809 |
+
cleanDataBtn.click(clear_be_csv_datas, outputs=be_csv_file_list).then(get_be_csv_files, outputs=be_csv_file_list)
|
810 |
tmp_msg.submit(pandas_analysis, [prompt_textbox, tmp_msg, tmp_chatbot], [tmp_msg, tmp_chatbot],queue=True)
|
811 |
tmp_clear.click(lambda: None, None, tmp_chatbot, queue=False)
|
812 |
with gr.Row():
|
813 |
gr.Examples([
|
814 |
+
'你有什麼欄位?'
|
|
|
|
|
|
|
815 |
], label="訊息範例", inputs=tmp_msg)
|
816 |
+
with gr.Row():
|
817 |
+
console = gr.Textbox(lines=11, label="Console", max_lines=11)
|
818 |
demo.queue(concurrency_count=10)
|
819 |
lunch_style(demo,console)
|
820 |
|