Change Liao
commited on
Commit
·
434ab25
1
Parent(s):
0952648
update the dependency and import error
Browse files- app.py +65 -20
- cache.sqlite3 +0 -0
- data/legal_quotation_prompt.txt +1 -1
- requirements.txt +1 -3
app.py
CHANGED
@@ -15,7 +15,7 @@ from sqlitedict import SqliteDict
|
|
15 |
|
16 |
import gradio as gr
|
17 |
|
18 |
-
from langchain import PromptTemplate, LLMChain
|
19 |
from langchain.agents import Tool
|
20 |
from langchain.agents import load_tools
|
21 |
from langchain.agents import initialize_agent
|
@@ -53,18 +53,18 @@ from langchain.document_loaders import YoutubeLoader
|
|
53 |
from azure_utils import AzureVoiceData
|
54 |
from polly_utils import PollyVoiceData, NEURAL_ENGINE
|
55 |
from contextlib import closing
|
56 |
-
from
|
57 |
import pandas as pd
|
58 |
|
59 |
#os env
|
60 |
os.environ["OPENAI_API_TYPE"] = "azure"
|
61 |
-
os.environ["OPENAI_API_VERSION"] = "
|
62 |
-
os.environ["OPENAI_API_BASE"] = "https://
|
63 |
-
os.environ["OPENAI_API_KEY"] = "
|
64 |
os.environ["SERPAPI_API_KEY"] = "a5b67b8805b4e12b0ae147c9c6b2a7dbf3ab84fca5f24e531b6963b1f7fc1ff7"
|
65 |
|
66 |
-
global_deployment_id = "gpt-
|
67 |
-
global_model_name = "gpt-
|
68 |
|
69 |
#chroma settings
|
70 |
chroma_api_impl = "HH_Azure_Openai"
|
@@ -123,11 +123,11 @@ def ai_answer(answer):
|
|
123 |
|
124 |
def get_openaiembeddings():
|
125 |
return OpenAIEmbeddings(
|
126 |
-
deployment="
|
127 |
model="text-embedding-ada-002",
|
128 |
-
openai_api_base="https://
|
129 |
openai_api_type="azure",
|
130 |
-
openai_api_key = "
|
131 |
chunk_size=1
|
132 |
)
|
133 |
|
@@ -302,7 +302,9 @@ def chat_conversation():
|
|
302 |
ai_response = chat(history.messages)
|
303 |
ai_answer(ai_response.content)
|
304 |
|
305 |
-
def local_vector_search(question_str,
|
|
|
|
|
306 |
embedding = get_openaiembeddings()
|
307 |
vectorstore = Chroma( embedding_function=embedding,
|
308 |
collection_name=collection_name,
|
@@ -321,7 +323,6 @@ def local_vector_search(question_str,chat_history, collection_name = hr_collecti
|
|
321 |
model_name= global_model_name,
|
322 |
temperature = 0.0)
|
323 |
|
324 |
-
|
325 |
prompt = PromptTemplate(
|
326 |
template=get_prompt_template_string(),
|
327 |
input_variables=["question","chat_history"]
|
@@ -600,6 +601,19 @@ def kh_update_km(files):
|
|
600 |
|
601 |
return num_of_collection(tmp_collection)
|
602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
603 |
class Logger:
|
604 |
def __init__(self, filename):
|
605 |
self.terminal = sys.stdout
|
@@ -646,7 +660,6 @@ def lunch_style(demo, logs=gr.Text()):
|
|
646 |
def gradio_run():
|
647 |
print("User Login")
|
648 |
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
649 |
-
|
650 |
with gr.Row():
|
651 |
gr.Markdown("# HH Azure Openai Demo")
|
652 |
#Header section
|
@@ -771,6 +784,7 @@ def gradio_run():
|
|
771 |
upload_button,
|
772 |
summary_text)
|
773 |
#3rd youtube
|
|
|
774 |
with gr.Tab("Youtube 影片摘要"):
|
775 |
with gr.Row():
|
776 |
with gr.Column(scale=1):
|
@@ -781,7 +795,9 @@ def gradio_run():
|
|
781 |
with gr.Column(scale=1):
|
782 |
youtube_summary_textbox=gr.Textbox(interactive=False, label="AI 解析", lines=20)
|
783 |
youtube_analysis_btn.click(youtube_summary,youtube_link,youtube_summary_textbox)
|
|
|
784 |
#4th 相信人員統計助手
|
|
|
785 |
with gr.Tab("相信人員統計助手"):
|
786 |
|
787 |
mypath = root_file_path + believe_source_path
|
@@ -859,7 +875,6 @@ def gradio_run():
|
|
859 |
'全台灣的員工, 每人每天問五個問題, 1個月花費多少錢?',
|
860 |
'如果龍華廠區的員工每人每天問3個問題,台灣員工每人每天問7個問題, 請問這樣一個月多少錢?'
|
861 |
], label="訊息範例", inputs=tmp_msg)
|
862 |
-
|
863 |
with gr.Tab("法務AI幫手"):
|
864 |
legal_path = "./data/"
|
865 |
quotation_file = "legal_quotation_prompt.txt"
|
@@ -924,11 +939,9 @@ def gradio_run():
|
|
924 |
label="2. Prompt",
|
925 |
interactive=True)
|
926 |
prompt_textbox.change(change_prompt, inputs=prompt_textbox)
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
with gr.Column():
|
931 |
-
restoreBtn = gr.Button("回覆預設Prompt")
|
932 |
|
933 |
gr.Markdown("""
|
934 |
---
|
@@ -953,6 +966,39 @@ def gradio_run():
|
|
953 |
upload_button.upload(upload_large_file, upload_button, file_name_field).\
|
954 |
then(change_prompt,inputs=prompt_textbox).\
|
955 |
then(summary_large_file, upload_button, summary_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
956 |
demo.queue(concurrency_count=10)
|
957 |
lunch_style(demo,console)
|
958 |
|
@@ -963,4 +1009,3 @@ def test():
|
|
963 |
|
964 |
gradio_run()
|
965 |
|
966 |
-
|
|
|
15 |
|
16 |
import gradio as gr
|
17 |
|
18 |
+
from langchain import PromptTemplate, LLMChain, ConversationChain
|
19 |
from langchain.agents import Tool
|
20 |
from langchain.agents import load_tools
|
21 |
from langchain.agents import initialize_agent
|
|
|
53 |
from azure_utils import AzureVoiceData
|
54 |
from polly_utils import PollyVoiceData, NEURAL_ENGINE
|
55 |
from contextlib import closing
|
56 |
+
from langchain.agents import create_pandas_dataframe_agent
|
57 |
import pandas as pd
|
58 |
|
59 |
#os env
|
60 |
os.environ["OPENAI_API_TYPE"] = "azure"
|
61 |
+
os.environ["OPENAI_API_VERSION"] = "2023-03-15-preview"
|
62 |
+
os.environ["OPENAI_API_BASE"] = "https://hh-azure-openai-poc.openai.azure.com/"
|
63 |
+
os.environ["OPENAI_API_KEY"] = "41dd3ccda6a2489db375f3fe2a440953"
|
64 |
os.environ["SERPAPI_API_KEY"] = "a5b67b8805b4e12b0ae147c9c6b2a7dbf3ab84fca5f24e531b6963b1f7fc1ff7"
|
65 |
|
66 |
+
global_deployment_id = "gpt-35-turbo-16k"
|
67 |
+
global_model_name = "gpt-35-turbo-16k"
|
68 |
|
69 |
#chroma settings
|
70 |
chroma_api_impl = "HH_Azure_Openai"
|
|
|
123 |
|
124 |
def get_openaiembeddings():
|
125 |
return OpenAIEmbeddings(
|
126 |
+
deployment="CivetGPT_embedding",
|
127 |
model="text-embedding-ada-002",
|
128 |
+
openai_api_base="https://civet-project-001.openai.azure.com/",
|
129 |
openai_api_type="azure",
|
130 |
+
openai_api_key = "0e3e5b666818488fa1b5cb4e4238ffa7",
|
131 |
chunk_size=1
|
132 |
)
|
133 |
|
|
|
302 |
ai_response = chat(history.messages)
|
303 |
ai_answer(ai_response.content)
|
304 |
|
305 |
+
def local_vector_search(question_str,
|
306 |
+
chat_history,
|
307 |
+
collection_name = hr_collection_name):
|
308 |
embedding = get_openaiembeddings()
|
309 |
vectorstore = Chroma( embedding_function=embedding,
|
310 |
collection_name=collection_name,
|
|
|
323 |
model_name= global_model_name,
|
324 |
temperature = 0.0)
|
325 |
|
|
|
326 |
prompt = PromptTemplate(
|
327 |
template=get_prompt_template_string(),
|
328 |
input_variables=["question","chat_history"]
|
|
|
601 |
|
602 |
return num_of_collection(tmp_collection)
|
603 |
|
604 |
+
def generate_autolayout(description, template):
|
605 |
+
llm = AzureChatOpenAI(
|
606 |
+
deployment_name=global_deployment_id,
|
607 |
+
model_name=global_model_name,
|
608 |
+
temperature=0.0)
|
609 |
+
_template= PromptTemplate(
|
610 |
+
input_variables=["text"], template=template
|
611 |
+
)
|
612 |
+
llm_chain = LLMChain(llm=llm, prompt=_template)
|
613 |
+
layout_output = llm_chain.run(description)
|
614 |
+
print(layout_output)
|
615 |
+
return layout_output
|
616 |
+
|
617 |
class Logger:
|
618 |
def __init__(self, filename):
|
619 |
self.terminal = sys.stdout
|
|
|
660 |
def gradio_run():
|
661 |
print("User Login")
|
662 |
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
|
|
663 |
with gr.Row():
|
664 |
gr.Markdown("# HH Azure Openai Demo")
|
665 |
#Header section
|
|
|
784 |
upload_button,
|
785 |
summary_text)
|
786 |
#3rd youtube
|
787 |
+
"""
|
788 |
with gr.Tab("Youtube 影片摘要"):
|
789 |
with gr.Row():
|
790 |
with gr.Column(scale=1):
|
|
|
795 |
with gr.Column(scale=1):
|
796 |
youtube_summary_textbox=gr.Textbox(interactive=False, label="AI 解析", lines=20)
|
797 |
youtube_analysis_btn.click(youtube_summary,youtube_link,youtube_summary_textbox)
|
798 |
+
"""
|
799 |
#4th 相信人員統計助手
|
800 |
+
|
801 |
with gr.Tab("相信人員統計助手"):
|
802 |
|
803 |
mypath = root_file_path + believe_source_path
|
|
|
875 |
'全台灣的員工, 每人每天問五個問題, 1個月花費多少錢?',
|
876 |
'如果龍華廠區的員工每人每天問3個問題,台灣員工每人每天問7個問題, 請問這樣一個月多少錢?'
|
877 |
], label="訊息範例", inputs=tmp_msg)
|
|
|
878 |
with gr.Tab("法務AI幫手"):
|
879 |
legal_path = "./data/"
|
880 |
quotation_file = "legal_quotation_prompt.txt"
|
|
|
939 |
label="2. Prompt",
|
940 |
interactive=True)
|
941 |
prompt_textbox.change(change_prompt, inputs=prompt_textbox)
|
942 |
+
|
943 |
+
saveBtn = gr.Button("保存現有Prompt")
|
944 |
+
restoreBtn = gr.Button("回覆預設Prompt")
|
|
|
|
|
945 |
|
946 |
gr.Markdown("""
|
947 |
---
|
|
|
966 |
upload_button.upload(upload_large_file, upload_button, file_name_field).\
|
967 |
then(change_prompt,inputs=prompt_textbox).\
|
968 |
then(summary_large_file, upload_button, summary_text)
|
969 |
+
with gr.Tab("AI layout"):
|
970 |
+
with gr.Row():
|
971 |
+
def change_prompt(inputString):
|
972 |
+
template_string = inputString
|
973 |
+
return template_string
|
974 |
+
def auto_layout(description, template):
|
975 |
+
html_string = generate_autolayout(description, template)
|
976 |
+
return html_string
|
977 |
+
with gr.Column(scale=1):
|
978 |
+
file_list = gr.Textbox(get_hr_files, label="1. 已存在知識庫的檔案",
|
979 |
+
placeholder="沒有任何檔案存在", max_lines=5, lines=5)
|
980 |
+
upload_button = gr.UploadButton("上傳UX/UI 知識庫檔案(text,pdf,docx,csv)",file_types=["text", ".pdf", ".docx", ".csv"],file_count="multiple")
|
981 |
+
upload_button.upload(update_hr_km, inputs=upload_button, outputs=file_list)
|
982 |
+
cleanDataBtn = gr.Button(value="刪除所有知識以及檔案")
|
983 |
+
cleanDataBtn.click(clear_hr_datas, outputs=file_list)
|
984 |
+
with gr.Column(scale=4):
|
985 |
+
autolayout_template = """你是一個資深的UX designer, 請依下方的需求,
|
986 |
+
給我一個web UI 的設計畫面, 使用html 語法; 除html 語法之外, 你不要說其他的話
|
987 |
+
|
988 |
+
需求:
|
989 |
+
'''
|
990 |
+
{text}
|
991 |
+
'''
|
992 |
+
"""
|
993 |
+
prompt_textbox = gr.Textbox(autolayout_template, lines=8, max_lines=8, label="2. Prompt")
|
994 |
+
update_btn = gr.Button("更新Prompt")
|
995 |
+
with gr.Row():
|
996 |
+
msg = gr.Textbox(placeholder="輸入說明讓AI 明白你想要的畫面", label="3. 描述")
|
997 |
+
with gr.Row():
|
998 |
+
content = gr.HTML("")
|
999 |
+
update_btn.click(change_prompt, prompt_textbox, prompt_textbox)
|
1000 |
+
msg.submit(auto_layout, [msg,prompt_textbox], content, queue=True)
|
1001 |
+
|
1002 |
demo.queue(concurrency_count=10)
|
1003 |
lunch_style(demo,console)
|
1004 |
|
|
|
1009 |
|
1010 |
gradio_run()
|
1011 |
|
|
cache.sqlite3
CHANGED
Binary files a/cache.sqlite3 and b/cache.sqlite3 differ
|
|
data/legal_quotation_prompt.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
你是一位超級助理, 十分擅長從大量文字中擷取摘要.
|
3 |
以下用 ''' 包含的是報價單的內容,幫我生成一份2,000個中文字以內報價單摘要,摘要需要包含以下項目:
|
4 |
|
5 |
-
1. 標的名稱:
|
6 |
2. 價格: 報價單中所列出的每個產品或服務的價格, 一定要有正確的幣別與金額數字.
|
7 |
3. 付款內容: 報價單中所列出的付款方式和相關內容, 包括訂金, 交貨款和保留款的金額和支付方式; 除了各款項的交付百分比, 也需要有正確的金額與幣別.
|
8 |
4. 交貨時間: 報價單中所列出的產品或服務的交付的日期或時間範圍。
|
|
|
2 |
你是一位超級助理, 十分擅長從大量文字中擷取摘要.
|
3 |
以下用 ''' 包含的是報價單的內容,幫我生成一份2,000個中文字以內報價單摘要,摘要需要包含以下項目:
|
4 |
|
5 |
+
1. 標的名稱: 報價單中所列出的產品或服務的名稱, 若是無法清楚識別正確的產品名稱或服務名稱, 請寫 '產品/名稱 無法辨識'
|
6 |
2. 價格: 報價單中所列出的每個產品或服務的價格, 一定要有正確的幣別與金額數字.
|
7 |
3. 付款內容: 報價單中所列出的付款方式和相關內容, 包括訂金, 交貨款和保留款的金額和支付方式; 除了各款項的交付百分比, 也需要有正確的金額與幣別.
|
8 |
4. 交貨時間: 報價單中所列出的產品或服務的交付的日期或時間範圍。
|
requirements.txt
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
boto3
|
2 |
sqlitedict
|
3 |
langchain
|
4 |
-
langchain_experimental
|
5 |
pandas
|
6 |
chroma
|
7 |
openai
|
@@ -13,5 +12,4 @@ pydantic==1.10.8
|
|
13 |
hnswlib
|
14 |
gradio_client==0.2.7
|
15 |
tiktoken
|
16 |
-
unstructured[all-docs]
|
17 |
-
numexpr
|
|
|
1 |
boto3
|
2 |
sqlitedict
|
3 |
langchain
|
|
|
4 |
pandas
|
5 |
chroma
|
6 |
openai
|
|
|
12 |
hnswlib
|
13 |
gradio_client==0.2.7
|
14 |
tiktoken
|
15 |
+
unstructured[all-docs]
|
|