Spaces:
Sleeping
Sleeping
File size: 2,564 Bytes
edff84f 112376f c1930c8 edff84f c1930c8 a7bef41 467479b a7bef41 308b157 edff84f fa6c371 112376f 308b157 edff84f 112376f edff84f 308b157 fa6c371 edff84f fa6c371 edff84f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import gradio as gr
from http import HTTPStatus
import os
import requests
import json
from dashscope import Application
def call_company(p):
prompt = p
response = Application.call(
# 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
api_key=os.getenv("DASHSCOPE_API_KEY"),
app_id=os.getenv("APP_ID"), # 替换为实际的应用 ID
prompt=prompt,
# biz_params=biz_params # 传递业务参数
)
if response.status_code != HTTPStatus.OK:
return response.message
else:
return response.output.text
URL="https://api.coze.cn/v3/chat"
HEADERS={"Authorization":os.getenv("COZE_TEMP"), "Content-Type":"application/json"}
def call_summary(p):
return "Working hard on it..."
def call_examine(p):
file_url = p
data = {
"bot_id": "7448073169124573218",
"user_id": "111",
"stream": False,
"auto_save_history": True,
"additional_messages":[
{
"role":"user",
"content":"[{\"type\":\"text\",\"text\":\"帮我分析一下广告图片\"},{\"type\":\"image\",\"file_url\":\""+ file_url + "\"}]",
"content_type":"object_string"
}
]
}
print(data)
# res = requests.post(URL, headers=HEADERS, data=json.dumps(data))
# print(res.json())
# print(res.json()['code'])
return """
- 📄 审核结果:通过
- 💬 问题说明:未发现违反广告法的内容。
- ✍️ 改进建议:无。
"""
def run_flow(scene, text):
print(scene, text)
if scene == "企业净调":
return call_company(text)
if scene == "企业舆情总结":
return call_summary(text)
if scene == "金融产品广告合规检查":
return call_examine(text)
else:
pass
with gr.Blocks() as demo:
gr.Markdown("# 💰金融场景AI助手")
with gr.Row():
with gr.Column():
scene = gr.Dropdown(
["企业净调", "企业舆情总结", "金融产品广告合规检查"], label="场景", info="请选择场景"
)
text = gr.Textbox(label="输入")
btn = gr.Button("开始")
with gr.Column():
result = gr.Markdown(label="结果", show_label=True, container=True, min_height=100)
btn.click(fn=run_flow, inputs=[scene, text], outputs=result)
demo.launch() |