Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,47 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from google import genai
|
| 3 |
import os
|
| 4 |
from dotenv import load_dotenv
|
|
|
|
| 5 |
|
| 6 |
load_dotenv(verbose=True)
|
| 7 |
|
| 8 |
-
def generate_content(prompt):
|
| 9 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
|
|
|
| 10 |
response = client.models.generate_content(
|
| 11 |
-
model="gemini-2.0-flash",
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
)
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Gradio Blocksの設定
|
| 17 |
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:
|
|
@@ -51,8 +81,8 @@ with gr.Blocks(title="gemini think",css="footer {visibility: hidden;} #header {d
|
|
| 51 |
</style>
|
| 52 |
</head>
|
| 53 |
<body>
|
| 54 |
-
<h1>Geminiの「Think」
|
| 55 |
-
<p>Geminiの「Think」
|
| 56 |
<ul>
|
| 57 |
<li><span class="highlight">複雑な問題解決:</span> 複数の仮説を立てて最適な解答を選択。</li>
|
| 58 |
<li><span class="highlight">階層化された思考:</span> 重要な情報を整理し、論理的な流れで提示。</li>
|
|
@@ -67,11 +97,12 @@ with gr.Blocks(title="gemini think",css="footer {visibility: hidden;} #header {d
|
|
| 67 |
with gr.Row():
|
| 68 |
prompt_input = gr.Textbox(label="プロンプトを入力してください", info="例: gbizinfoについて説明して、合わせて利用料金に関しても教えてください。")
|
| 69 |
output_text = gr.Textbox(label="生成されたレスポンス", info="gemini thinkで生成された結果が表示されます。")
|
|
|
|
| 70 |
|
| 71 |
with gr.Row():
|
| 72 |
generate_button = gr.Button("生成")
|
| 73 |
|
| 74 |
# ボタン動作
|
| 75 |
-
generate_button.click(generate_content, inputs=prompt_input, outputs=output_text)
|
| 76 |
|
| 77 |
gemini.launch(favicon_path="favicon.ico")
|
|
|
|
| 1 |
+
#pip3 install googletrans==4.0.0-rc1
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
from google import genai
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
+
from googletrans import Translator
|
| 8 |
|
| 9 |
load_dotenv(verbose=True)
|
| 10 |
|
| 11 |
+
async def generate_content(prompt):
|
| 12 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
| 13 |
+
config = {'thinking_config': {'include_thoughts': True}}
|
| 14 |
response = client.models.generate_content(
|
| 15 |
+
#model="gemini-2.0-flash",
|
| 16 |
+
model='gemini-2.0-flash-thinking-exp',
|
| 17 |
+
contents=prompt,
|
| 18 |
+
config=config
|
| 19 |
)
|
| 20 |
+
|
| 21 |
+
summary_thought = ""
|
| 22 |
+
summary_answer = ''
|
| 23 |
+
|
| 24 |
+
translator = Translator()
|
| 25 |
+
summary_thought = ""
|
| 26 |
+
summary_answer = ""
|
| 27 |
+
|
| 28 |
+
for part in response.candidates[0].content.parts:
|
| 29 |
+
if not part.text:
|
| 30 |
+
continue
|
| 31 |
+
translated_text = await translator.translate(part.text, src='en', dest='ja')
|
| 32 |
+
if part.thought:
|
| 33 |
+
print("考えの要約:")
|
| 34 |
+
print(translated_text)
|
| 35 |
+
print()
|
| 36 |
+
summary_thought += translated_text.text
|
| 37 |
+
else:
|
| 38 |
+
print("答え:")
|
| 39 |
+
print(translated_text)
|
| 40 |
+
print()
|
| 41 |
+
summary_answer += translated_text.text
|
| 42 |
+
|
| 43 |
+
summaries = summary_thought + '\n' + summary_answer
|
| 44 |
+
return response.text,summaries
|
| 45 |
|
| 46 |
# Gradio Blocksの設定
|
| 47 |
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:
|
|
|
|
| 81 |
</style>
|
| 82 |
</head>
|
| 83 |
<body>
|
| 84 |
+
<h1>Geminiの「Think」機能</h1>
|
| 85 |
+
<p>Geminiの「Think」機能は、GoogleのAIモデルに搭載されている高度な推論と計画能力を指します。特に、複雑なタスクに役立つように設計されています。</p>
|
| 86 |
<ul>
|
| 87 |
<li><span class="highlight">複雑な問題解決:</span> 複数の仮説を立てて最適な解答を選択。</li>
|
| 88 |
<li><span class="highlight">階層化された思考:</span> 重要な情報を整理し、論理的な流れで提示。</li>
|
|
|
|
| 97 |
with gr.Row():
|
| 98 |
prompt_input = gr.Textbox(label="プロンプトを入力してください", info="例: gbizinfoについて説明して、合わせて利用料金に関しても教えてください。")
|
| 99 |
output_text = gr.Textbox(label="生成されたレスポンス", info="gemini thinkで生成された結果が表示されます。")
|
| 100 |
+
summary_text = gr.Textbox(label="サマリー", info="gemini thinkで生成されたサマリー結果が表示されます。")
|
| 101 |
|
| 102 |
with gr.Row():
|
| 103 |
generate_button = gr.Button("生成")
|
| 104 |
|
| 105 |
# ボタン動作
|
| 106 |
+
generate_button.click(generate_content, inputs=prompt_input, outputs=[output_text,summary_text])
|
| 107 |
|
| 108 |
gemini.launch(favicon_path="favicon.ico")
|