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()