File size: 4,406 Bytes
d191fff
8b0f57e
 
 
 
d191fff
8b0f57e
 
 
d191fff
8b0f57e
d191fff
8b0f57e
502ebef
d191fff
 
 
8b0f57e
d191fff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502ebef
 
8b0f57e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d191fff
 
8b0f57e
 
 
 
 
 
 
 
 
 
 
 
502ebef
 
 
8b0f57e
 
 
 
 
d191fff
8b0f57e
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pip3 install googletrans==4.0.0-rc1
import gradio as gr
from google import genai
import os
from dotenv import load_dotenv
from googletrans import Translator

load_dotenv(verbose=True) 

async def generate_content(prompt):
    client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
    config = {'thinking_config': {'include_thoughts': True}}
    response = client.models.generate_content(
        #model="gemini-2.5-flash",
        model='gemini-2.0-flash-thinking-exp',
        contents=prompt,
        config=config
    )

    summary_thought = ""
    summary_answer = ''

    translator = Translator()
    summary_thought = ""
    summary_answer = ""

    for part in response.candidates[0].content.parts:
        if not part.text:
            continue
        translated_text = await translator.translate(part.text, src='en', dest='ja')
        if part.thought:
            summary_thought += translated_text.text
        else:
            summary_answer += translated_text.text

        summaries = summary_thought + '\n' + summary_answer
    
    return summary_thought,summary_answer

# Gradio Blocksの設定
with gr.Blocks(title="gemini think",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;} .logout-btn { background-color: #3498db; border-radius: 10px; color: white; padding: 10px 20px; border: none; cursor: pointer; transparent-bg {background-color: transparent; color: black; padding: 10px; border: none;}") as gemini:
    gr.Markdown("### プロンプトで依頼した内容の説明を生成します - gemini think")

    with gr.Sidebar(open=False):
        gr.HTML('''
        <!DOCTYPE html>
        <html lang="ja">
        <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Gemini Think 機能について</title>
        <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 20px;
            background-color: #f9f9f9;
        }
        h1 {
            color: #333;
        }
        ul {
            background-color: #fff;
            padding: 15px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }
        li {
            margin: 10px 0;
        }
        .highlight {
            font-weight: bold;
            color: #007BFF;
        }
        </style>
        </head>
        <body>
        <h1>Geminiの「Think」機能</h1>
        <p>Geminiの「Think」機能は、GoogleのAIモデルに搭載されている高度な推論と計画能力を指します。特に、複雑なタスクに役立つように設計されています。</p>
        <ul>
        <li><span class="highlight">複雑な問題解決:</span> 複数の仮説を立てて最適な解答を選択。</li>
        <li><span class="highlight">階層化された思考:</span> 重要な情報を整理し、論理的な流れで提示。</li>
        <li><span class="highlight">動的思考:</span> タスクの複雑さに応じて思考の深さを調整。</li>
        </ul>
        <p>これにより、数学的な問題やコーディング、戦略的な計画などに特に効果的です。</p>
        <p>オプションとして、<span class="highlight">「thinkingBudget」</span>を設定することで、使用するリソースを柔軟に管理できます。</p>
        </body>
        </html>
        ''')
    
    with gr.Row():
        prompt_input = gr.Textbox(label="プロンプトを入力してください", info="例: すき家は色々な問題がりました。結果、客数も減り、経営上、大きな問題が浮上しました。これらを改善し、経営を正常化するにはどんな打ち手があるか教えてください。")
        output_text = gr.Textbox(label="生成されたThought", info="gemini thinkで生成されたthoghtが表示されます。")
        summary_text = gr.Textbox(label="結果", info="gemini thinkで生成された結果が表示されます。")

    with gr.Row():
        generate_button = gr.Button("生成")

    # ボタン動作
    generate_button.click(generate_content, inputs=prompt_input, outputs=[output_text,summary_text])

gemini.launch(favicon_path="favicon.ico")