zcfrank1st commited on
Commit
edff84f
·
verified ·
1 Parent(s): 95ca334

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from http import HTTPStatus
3
+ import os
4
+
5
+ from dashscope import Application
6
+
7
+ def call_company(p):
8
+ prompt = p
9
+ response = Application.call(
10
+ # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
11
+ api_key=os.getenv("DASHSCOPE_API_KEY"),
12
+ app_id=os.getenv("APP_ID"), # 替换为实际的应用 ID
13
+ prompt=prompt,
14
+ # biz_params=biz_params # 传递业务参数
15
+ )
16
+
17
+ if response.status_code != HTTPStatus.OK:
18
+ return response.message
19
+ else:
20
+ return response.output.text
21
+
22
+
23
+ def run_flow(input_value):
24
+ if input_value == "公司净调":
25
+ return call_company(input_value)
26
+ else:
27
+ pass
28
+
29
+ with gr.Blocks() as demo:
30
+ gr.Markdown("# 💰金融场景AI助手")
31
+ with gr.Row():
32
+ with gr.Column():
33
+ scene = gr.Dropdown(
34
+ ["公司净调", ], label="场景", info="请选择场景"
35
+ ),
36
+ text = gr.Textbox(label="输入")
37
+ btn = gr.Button("开始")
38
+ with gr.Column():
39
+ result = gr.Textbox(label="结果")
40
+ btn.click(fn=run_flow, inputs=scene, outputs=result)
41
+
42
+ demo.launch()