Spaces:
Running
Running
Change to flexible target_type & target_value
Browse files- api_calls.py +6 -4
- app.py +19 -11
api_calls.py
CHANGED
@@ -20,24 +20,26 @@ def call_api(api_path, api_params):
|
|
20 |
)
|
21 |
return response.json()
|
22 |
|
23 |
-
def api_rag_qa_chain_demo(openai_model_name, query, year,
|
24 |
api_path = "qa/demo"
|
25 |
api_params = {
|
26 |
"openai_model_name": openai_model_name,
|
27 |
"query": query,
|
28 |
"year": year,
|
29 |
-
"
|
|
|
30 |
"prev_turn_of_conversation": history,
|
31 |
}
|
32 |
return call_api_stream(api_path, api_params)
|
33 |
|
34 |
-
def api_rag_summ_chain_demo(openai_model_name, query, year,
|
35 |
api_path = "summary/demo"
|
36 |
api_params = {
|
37 |
"openai_model_name": openai_model_name,
|
38 |
"query": query,
|
39 |
"year": year,
|
40 |
-
"
|
|
|
41 |
"tone": tone,
|
42 |
}
|
43 |
return call_api_stream(api_path, api_params)
|
|
|
20 |
)
|
21 |
return response.json()
|
22 |
|
23 |
+
def api_rag_qa_chain_demo(openai_model_name, query, year, target_type, target_value, history):
|
24 |
api_path = "qa/demo"
|
25 |
api_params = {
|
26 |
"openai_model_name": openai_model_name,
|
27 |
"query": query,
|
28 |
"year": year,
|
29 |
+
"target_type": target_type,
|
30 |
+
"target_value": target_value,
|
31 |
"prev_turn_of_conversation": history,
|
32 |
}
|
33 |
return call_api_stream(api_path, api_params)
|
34 |
|
35 |
+
def api_rag_summ_chain_demo(openai_model_name, query, year, target_type, target_value, tone):
|
36 |
api_path = "summary/demo"
|
37 |
api_params = {
|
38 |
"openai_model_name": openai_model_name,
|
39 |
"query": query,
|
40 |
"year": year,
|
41 |
+
"target_type": target_type,
|
42 |
+
"target_value": target_value,
|
43 |
"tone": tone,
|
44 |
}
|
45 |
return call_api_stream(api_path, api_params)
|
app.py
CHANGED
@@ -29,9 +29,9 @@ def add_text(history, text):
|
|
29 |
history = history + [(text, None)]
|
30 |
return history, gr.Textbox(value="", interactive=False)
|
31 |
|
32 |
-
def esgsumm_exe(openai_model_name, year,
|
33 |
query = "根據您提供的相關資訊和偏好語氣,以繁體中文生成一份符合GRI標準的報告草稿。報告將包括每個GRI披露項目的標題、相關公司行為的概要,以及公司的具體措施和效果。"
|
34 |
-
response = api_rag_summ_chain_demo(openai_model_name, query, year,
|
35 |
full_anwser = ""
|
36 |
for chunk in response.iter_content(chunk_size=32):
|
37 |
if chunk:
|
@@ -45,9 +45,9 @@ def esgsumm_exe(openai_model_name, year, company_name, tone):
|
|
45 |
# full_text += character
|
46 |
# yield full_text
|
47 |
|
48 |
-
def esgqabot(history, openai_model_name, year,
|
49 |
query = history[-1][0]
|
50 |
-
response = api_rag_qa_chain_demo(openai_model_name, query, year,
|
51 |
history[-1][1] = ""
|
52 |
for chunk in response.iter_content(chunk_size=32):
|
53 |
if chunk:
|
@@ -89,8 +89,12 @@ with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green", primary_
|
|
89 |
label="Year",
|
90 |
choices=["111", "110", "109"]
|
91 |
)
|
92 |
-
|
93 |
-
label="
|
|
|
|
|
|
|
|
|
94 |
choices=["台泥", "聯電", "裕融", "大同", "台積電", "鴻海", "中鋼", "中華電信"]
|
95 |
)
|
96 |
esgsumm_report_gen_button = gr.Button("Generate Report")
|
@@ -129,8 +133,12 @@ with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green", primary_
|
|
129 |
label="Year",
|
130 |
choices=["111", "110", "109"]
|
131 |
)
|
132 |
-
|
133 |
-
label="
|
|
|
|
|
|
|
|
|
134 |
choices=["台泥", "聯電", "裕融", "大同", "台積電", "鴻海", "中鋼", "中華電信"]
|
135 |
)
|
136 |
|
@@ -163,7 +171,7 @@ with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green", primary_
|
|
163 |
|
164 |
# esgsumm
|
165 |
esgsumm_report_gen_button.click(
|
166 |
-
esgsumm_exe, [esgsumm_openai_model_name, esgsumm_year,
|
167 |
).then(
|
168 |
markdown2html, [esgsumm_report_output], [esgsumm_report_output_html]
|
169 |
)
|
@@ -177,14 +185,14 @@ with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green", primary_
|
|
177 |
esgqa_chatbot_input.submit(
|
178 |
add_text, [esgqa_chatbot, esgqa_chatbot_input], [esgqa_chatbot, esgqa_chatbot_input], queue=False
|
179 |
).then(
|
180 |
-
esgqabot, [esgqa_chatbot, esgqa_openai_model_name, esgqa_year,
|
181 |
).then(
|
182 |
lambda: gr.Textbox(interactive=True), None, [esgqa_chatbot_input], queue=False
|
183 |
)
|
184 |
esgqa_chat_btn.click(
|
185 |
add_text, [esgqa_chatbot, esgqa_chatbot_input], [esgqa_chatbot, esgqa_chatbot_input], queue=False
|
186 |
).then(
|
187 |
-
esgqabot, [esgqa_chatbot, esgqa_openai_model_name, esgqa_year,
|
188 |
).then(
|
189 |
lambda: gr.Textbox(interactive=True), None, [esgqa_chatbot_input], queue=False
|
190 |
)
|
|
|
29 |
history = history + [(text, None)]
|
30 |
return history, gr.Textbox(value="", interactive=False)
|
31 |
|
32 |
+
def esgsumm_exe(openai_model_name, year, target_type, target_value, tone):
|
33 |
query = "根據您提供的相關資訊和偏好語氣,以繁體中文生成一份符合GRI標準的報告草稿。報告將包括每個GRI披露項目的標題、相關公司行為的概要,以及公司的具體措施和效果。"
|
34 |
+
response = api_rag_summ_chain_demo(openai_model_name, query, year, target_type, target_value, tone)
|
35 |
full_anwser = ""
|
36 |
for chunk in response.iter_content(chunk_size=32):
|
37 |
if chunk:
|
|
|
45 |
# full_text += character
|
46 |
# yield full_text
|
47 |
|
48 |
+
def esgqabot(history, openai_model_name, year, target_type, target_value):
|
49 |
query = history[-1][0]
|
50 |
+
response = api_rag_qa_chain_demo(openai_model_name, query, year, target_type, target_value, history[:-1])
|
51 |
history[-1][1] = ""
|
52 |
for chunk in response.iter_content(chunk_size=32):
|
53 |
if chunk:
|
|
|
89 |
label="Year",
|
90 |
choices=["111", "110", "109"]
|
91 |
)
|
92 |
+
esgsumm_target_type = gr.Dropdown(
|
93 |
+
label="Target Type",
|
94 |
+
choices=["company_name", "industry"]
|
95 |
+
)
|
96 |
+
esgsumm_target_value = gr.Dropdown(
|
97 |
+
label="Target Value",
|
98 |
choices=["台泥", "聯電", "裕融", "大同", "台積電", "鴻海", "中鋼", "中華電信"]
|
99 |
)
|
100 |
esgsumm_report_gen_button = gr.Button("Generate Report")
|
|
|
133 |
label="Year",
|
134 |
choices=["111", "110", "109"]
|
135 |
)
|
136 |
+
esgqa_target_type = gr.Dropdown(
|
137 |
+
label="Target Type",
|
138 |
+
choices=["company_name", "industry"]
|
139 |
+
)
|
140 |
+
esgqa_target_value = gr.Dropdown(
|
141 |
+
label="Target Value",
|
142 |
choices=["台泥", "聯電", "裕融", "大同", "台積電", "鴻海", "中鋼", "中華電信"]
|
143 |
)
|
144 |
|
|
|
171 |
|
172 |
# esgsumm
|
173 |
esgsumm_report_gen_button.click(
|
174 |
+
esgsumm_exe, [esgsumm_openai_model_name, esgsumm_year, esgsumm_target_type, esgsumm_target_value, esgsumm_report_tone], [esgsumm_report_output]
|
175 |
).then(
|
176 |
markdown2html, [esgsumm_report_output], [esgsumm_report_output_html]
|
177 |
)
|
|
|
185 |
esgqa_chatbot_input.submit(
|
186 |
add_text, [esgqa_chatbot, esgqa_chatbot_input], [esgqa_chatbot, esgqa_chatbot_input], queue=False
|
187 |
).then(
|
188 |
+
esgqabot, [esgqa_chatbot, esgqa_openai_model_name, esgqa_year, esgqa_target_type, esgqa_target_value], esgqa_chatbot, api_name="esgqa_response"
|
189 |
).then(
|
190 |
lambda: gr.Textbox(interactive=True), None, [esgqa_chatbot_input], queue=False
|
191 |
)
|
192 |
esgqa_chat_btn.click(
|
193 |
add_text, [esgqa_chatbot, esgqa_chatbot_input], [esgqa_chatbot, esgqa_chatbot_input], queue=False
|
194 |
).then(
|
195 |
+
esgqabot, [esgqa_chatbot, esgqa_openai_model_name, esgqa_year, esgqa_target_type, esgqa_target_value], esgqa_chatbot, api_name="esgqa_response"
|
196 |
).then(
|
197 |
lambda: gr.Textbox(interactive=True), None, [esgqa_chatbot_input], queue=False
|
198 |
)
|