import gradio as gr import os from dotenv import load_dotenv from google import genai load_dotenv(verbose=True) google_api_key = os.environ.get("GEMINI_API_KEY") client = genai.Client(api_key=google_api_key) template = """ Executive Report - Liquid Glass Edition
Quarterly Report 2024

マーケティング戦略
進捗報告書

社外秘

💡 Key Insight

過去3ヶ月の施策により、リード獲得コストは25%削減されました。 次四半期は、現在のLiquid Glassデザインを導入したLPのABテストを強化し、CVRの更なる向上を目指します。

総リード数 1,240 +12%
CPA(獲得単価) ¥4,200 -8%
成約率 4.8% +1.2%

今後の重点施策

市場のトレンドは「視覚的な透明感」と「信頼性」の両立に移行しています。 本報告書で採用しているデザインコンセプトは、ユーザーに清潔感とモダンな印象を与え、滞在時間の延長に寄与します。

""" meta_prompt = ''' 思考のガイドライン 文脈の理解: ユーザーの意図、背景、制約条件を正確に把握してください。 推論の先行: 結論を出す前に、必ず「なぜその結論に至るのか」という思考のプロセスを記述してください。 多角的視点: 表面的な回答だけでなく、潜在的な課題や代替案、リスクについても考慮してください。 論理的整合性: ステップ間のつながりを明確にし、矛盾がないかセルフチェックを行ってください。 実行ステップ 1. タスクの分解と分析 実行すべきタスクを最小単位の要素に分解してください。 必要な情報、使用すべきトーン、守るべきルールを明確にします。 2. 推論と戦略立案(Reasoning) 結論に至るまでの論理的な道筋を立ててください。 複数のアプローチがある場合は、最も適切なものを選択した理由を明記してください。 計算や複雑な論理が必要な場合は、ここでステップバイステップで展開してください。 3. 検証と洗練 生成した解決策が、すべての制約条件を満たしているか確認してください。 より簡潔に、あるいはより強力にできる部分を修正してください。 出力形式 以下の構造で回答してください。 推論プロセス(Reasoning) [タスクの分析、論理的な思考、解決までのステップを詳細に記述してください。] 最終回答(Conclusion/Result) [推論に基づいた最終的な成果物を出力してください。形式はタスクに応じて最適化してください(JSON、マークダウン、文章など)。] ''' def save_report(html_content): filename = "report_output.html" with open(filename, "w", encoding="utf-8") as f: f.write(html_content) return filename # --- Gradio UI Logic --- def generate_response(query): prompt = f"{meta_prompt}に基づいて{query}に対する答えを必ず、{template}に基づいてHTML形式で出力してください。回答が見つからない場合は、ウェブで検索して{meta_prompt}に基づいて必ず、{template}に基づいてHTML形式で回答してください。" gresponse = client.models.generate_content( model="gemini-2.5-flash", contents=[prompt] ) myresp = gresponse.text part1 = myresp.find('```html') part2 = myresp.rfind('```') first_part = myresp[:part1] second_part = myresp[part1+7:part2] return first_part, second_part, second_part, gr.update(visible=True), gr.update(visible=True) # --- Gradio UI setup --- with gr.Blocks(title="メタプロンプト", theme=gr.themes.Glass(), css="""footer {visibility: hidden;} #header {display: flex; justify-content: space-between; align-items: center; font-size: 24px; font-weight: bold;} #logo {width: 50px; height: 50px;} #html_output_box {max-height: 600px; overflow-y: auto; border: 1px solid #e5e7eb; padding: 10px; border-radius: 8px;}""") as dob: gr.HTML('') gr.Markdown("メタプロンプトを利用して答えを生成できます。") html_state = gr.State("") with gr.Row(): prompt_input = gr.Textbox( label="プロンプト", info="最近のスマートフォンのトレンドや市場動向を考慮して回答してください。" ) with gr.Row(): log_output = gr.Textbox( label="回答", lines=20, interactive=False, max_lines=5, show_copy_button=True ) html_output = gr.HTML(elem_id="html_output_box") with gr.Row(): with gr.Row(): process_button = gr.Button("🤖 実行", variant="primary") with gr.Row(): print_btn = gr.Button("保存", visible=False) file_output = gr.File(label="ダウンロード用リンク", visible=False) print_btn.click(fn=save_report, inputs=html_state, outputs=file_output) process_button.click( fn=generate_response, inputs=[prompt_input], outputs=[log_output, html_output, html_state, print_btn, file_output] ) dob.launch(favicon_path="favicon.ico", show_api=False)