Wallacechu commited on
Commit
d9993fc
·
verified ·
1 Parent(s): ee41e4c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +45 -0
  2. data.txt +46 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from sentence_transformers import SentenceTransformer
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
+ import faiss
5
+ import numpy as np
6
+ import torch
7
+
8
+ # 1️⃣ 載入文本資料
9
+ with open("data.txt", "r", encoding="utf-8") as f:
10
+ docs = f.readlines()
11
+
12
+ # 2️⃣ 建立文本向量
13
+ embedder = SentenceTransformer("all-MiniLM-L6-v2")
14
+ doc_embeddings = embedder.encode(docs, convert_to_numpy=True)
15
+
16
+ # 3️⃣ 建立 FAISS 向量索引
17
+ index = faiss.IndexFlatL2(doc_embeddings.shape[1])
18
+ index.add(doc_embeddings)
19
+
20
+ # 4️⃣ 載入中文生成模型
21
+ model_name = "IDEA-CCNL/Wenzhong-GPT2-110M"
22
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
23
+ model = AutoModelForCausalLM.from_pretrained(model_name)
24
+ generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
25
+
26
+ # 5️⃣ 定義 RAG 聊天功能
27
+ def rag_chat(question):
28
+ q_emb = embedder.encode([question], convert_to_numpy=True)
29
+ D, I = index.search(q_emb, k=2) # 找出最相關的 2 句
30
+ context = "\n".join([docs[i].strip() for i in I[0]])
31
+ prompt = f"根據以下資料回答問題:\n{context}\n\n問題:{question}\n答案:"
32
+ output = generator(prompt, max_length=120, num_return_sequences=1, do_sample=True)[0]["generated_text"]
33
+ return output
34
+
35
+ # 6️⃣ 建立 Gradio 介面
36
+ demo = gr.Interface(
37
+ fn=rag_chat,
38
+ inputs=gr.Textbox(label="輸入你的問題", placeholder="例如:RAG 是什麼?"),
39
+ outputs=gr.Textbox(label="模型回答"),
40
+ title="🧠 中文 RAG 聊天機器人",
41
+ description="這個模型會根據提供的文本資料找出相關資訊,並用中文回答。"
42
+ )
43
+
44
+ if __name__ == "__main__":
45
+ demo.launch()
data.txt ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Wallace is a passionate enabler, and the ESG product manager at TDCC since 2018. With 4-year dedication to this field, he has developed ESG investment solutions which are widely used by market participants. As a passionate partnership builder, day to day he talks to and works closely with users, vendors, regulators and other stakeholders.
2
+
3
+ In 2022 he spent much time ensuring the development of the TDCC ESG product team, a small team of three, through coaching, training, and leadership development. He participated in most ESG-related steering committees, contributing to the development of high-level ESG strategies in Taiwan.
4
+
5
+ He joined TDCC in 2014 as a Corporate Strategy Associate specializing in fintech regulations. He earned a Master degree in intellectual property, a Bachelor degree in law, and another Bachelor degree in Finance, from National Chengchi University, Taiwan.
6
+
7
+
8
+ Taiwan Depository & Clearing Corporation
9
+ Taiwan Depository & Clearing CorporationTaiwan Depository & Clearing Corporation
10
+ ��¾ �P 11 �~ 1 �Ӥ��¾ �P 11 �~ 1 �Ӥ�
11
+
12
+ Assistant Manager | Issuer Services Department Assistant Manager | Issuer Services Department
13
+ 2024�~5�� - �{�b �P 1 �~ 7 �Ӥ�2024�~5�� �ܤ� �P 1 �~ 7 �Ӥ�
14
+ Senior Associate | ESG Product Manager Senior Associate | ESG Product Manager
15
+ 2017�~11�� - 2024�~4�� �P 6 �~ 6 �Ӥ�2017�~11�� �� 2024�~4�� �P 6 �~ 6 �Ӥ�
16
+ --Develop web-based ESG solutions that involve multiple data sources and align with the regulator's expectations
17
+ --Develop the team to implement the product roadmap and marketing, especially focusing on expanding partnerships with international stakeholders
18
+ --Communicate with companies and investors on rating methodology and strategies; with the regulator and the exchange on market practices
19
+ --Provide insights on proxy voting, from voting policies, investors' expectations and detailed process to the regulator, companies and other stakeholders
20
+
21
+ Worthy to Note
22
+ --The solutions have been widely used by hundreds of domestic institutional users
23
+ --Provided advisory opinions to more than 100 companies, and frequently spoke before domestic and regional conferences and webinars, including delivering a speech before foreign stock exchanges
24
+ --Built up cooperation between all major ESG rating agencies and proxy advisors globally
25
+ --Be appointed by the regulator to lead projects to draft national voting benchmark policy and code of conduct for domestic ESG rating providers
26
+
27
+ Reported by "Moral Money" column in Financial Times | Taiwan research paper by Fitch Ratings | Regulatory update by ICI global | and several trade media
28
+
29
+ Associate | Corporate StrategyAssociate | Corporate Strategy
30
+ 2014�~11�� - 2017�~10�� �P 3 �~2014�~11�� �� 2017�~10�� �P 3 �~
31
+ --Organize and oversee the Company��s research projects. Several working papers were published in the Company��s magazine.
32
+ --Manage public relation affairs with domestic stakeholders--Organize and oversee the Company��s research projects. Several working papers were published in the Company��s magazine. --Manage public relation affairs with domestic stakeholders
33
+
34
+ Research Assistant | Graduate Student
35
+ Research Assistant | Graduate StudentResearch Assistant | Graduate Student
36
+ Taiwan Securities Association (TSA) | Taiwan Depository & Clearing Corporation (TDCC) ��¾Taiwan Securities Association (TSA) | Taiwan Depository & Clearing Corporation (TDCC) ��¾ 2013�~1�� - 2013�~12�� �P 1 �~2013�~1�� �� 2013�~12�� �P 1 �~
37
+
38
+ 2013 | Taiwan Securities Association (TSA)
39
+ Research Project " Rational Segmentation of Self-discipline, Heteronomy and Corporate Governance Mechanism��
40
+
41
+ --Responsible for summarizing cases from U.S. Court of Appeal about whether ��Double Jeopardy�� apply to securities companies and legal nature of sanctions decided by SEC, stock exchange, and regulatory authorities
42
+
43
+ 2013 | Taiwan Depository & Clearing Corporation
44
+ Research Project "Principles and Problems to Virtual Shareholder Meetings��
45
+
46
+ --Independently responsible for comprehensive research of laws, cases and corporate practice for shareholder meetings and proxy vote in Japan, compared and analyzed potential problems to adopt virtual meetings in Taiwan.
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ sentence-transformers
3
+ faiss-cpu
4
+ gradio
5
+ torch