zcfrank1st commited on
Commit
c1930c8
·
verified ·
1 Parent(s): 9a7530a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -3
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from http import HTTPStatus
3
  import os
4
  import requests
 
5
 
6
  from dashscope import Application
7
 
@@ -31,8 +32,8 @@ def call_examine(p):
31
  data = {
32
  "bot_id": "7448073169124573218",
33
  "user_id": "111",
34
- "stream": "false",
35
- "auto_save_history": "true",
36
  "additional_messages":[
37
  {
38
  "role":"user",
@@ -44,7 +45,86 @@ def call_examine(p):
44
 
45
  print(data)
46
 
47
- res = requests.post(URL, headers=HEADERS, data=data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  print(res.json())
50
  print(res.json()['code'])
 
2
  from http import HTTPStatus
3
  import os
4
  import requests
5
+ import json
6
 
7
  from dashscope import Application
8
 
 
32
  data = {
33
  "bot_id": "7448073169124573218",
34
  "user_id": "111",
35
+ "stream": False,
36
+ "auto_save_history": True,
37
  "additional_messages":[
38
  {
39
  "role":"user",
 
45
 
46
  print(data)
47
 
48
+ res = requests.post(URL, headers=HEADERS, data=json.dumps(data))
49
+
50
+ print(res.json())
51
+ print(res.json()['code'])
52
+ return "Working hard on it..."
53
+
54
+
55
+ def run_flow(scene, text):
56
+ print(scene, text)
57
+ if scene == "企业净调":
58
+ return call_company(text)
59
+ if scene == "企业舆情总结":
60
+ return call_summary(text)
61
+ if scene == "金融产品广告合规检查":
62
+ return call_examine(text)
63
+ else:
64
+ pass
65
+
66
+ with gr.Blocks() as demo:
67
+ gr.Markdown("# 💰金融场景AI助手")
68
+ with gr.Row():
69
+ with gr.Column():
70
+ scene = gr.Dropdown(
71
+ ["企业净调", "企业舆情总结", "金融产品广告合规检查"], label="场景", info="请选择场景"
72
+ )
73
+ text = gr.Textbox(label="输入")
74
+ btn = gr.Button("开始")
75
+ with gr.Column():
76
+ result = gr.Markdown(label="结果", show_label=True, container=True, min_height=100)
77
+
78
+ btn.click(fn=run_flow, inputs=[scene, text], outputs=result)
79
+
80
+ demo.launch()import gradio as gr
81
+ from http import HTTPStatus
82
+ import os
83
+ import requests
84
+ import json
85
+
86
+ from dashscope import Application
87
+
88
+ def call_company(p):
89
+ prompt = p
90
+ response = Application.call(
91
+ # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
92
+ api_key=os.getenv("DASHSCOPE_API_KEY"),
93
+ app_id=os.getenv("APP_ID"), # 替换为实际的应用 ID
94
+ prompt=prompt,
95
+ # biz_params=biz_params # 传递业务参数
96
+ )
97
+
98
+ if response.status_code != HTTPStatus.OK:
99
+ return response.message
100
+ else:
101
+ return response.output.text
102
+
103
+ URL="https://api.coze.cn/v3/chat"
104
+ HEADERS={"Authorization":os.getenv("COZE_TEMP"), "Content-Type":"application/json"}
105
+
106
+ def call_summary(p):
107
+ return "Working hard on it..."
108
+
109
+ def call_examine(p):
110
+ file_url = p
111
+ data = {
112
+ "bot_id": "7448073169124573218",
113
+ "user_id": "111",
114
+ "stream": False,
115
+ "auto_save_history": True,
116
+ "additional_messages":[
117
+ {
118
+ "role":"user",
119
+ "content":"[{\"type\":\"text\",\"text\":\"帮我分析一下广告图片\"},{\"type\":\"image\",\"file_url\":\""+ file_url + "\"}]",
120
+ "content_type":"object_string"
121
+ }
122
+ ]
123
+ }
124
+
125
+ print(data)
126
+
127
+ res = requests.post(URL, headers=HEADERS, data=json.dumps(data))
128
 
129
  print(res.json())
130
  print(res.json()['code'])