見出し画像

Google Geminiってめっちゃ便利!

Geminiって最高

英語の勉強で新しく学んだ英語の例文を作るのにChatGPTを使ってたけど、最近Geminiが無料なのでGoogle AI StudioでGemini 1.5 Proを使ってた。
適切に英単語を認識するし、例文も日本語和訳もいい感じ。便利で毎日使ってます。

ふと、複数の単語を入力して、各々の英語例文と日本語和訳を出力してくれると便利だなーと思い、Google ColabでAPIを使ってみよーと思って使ってみました。

これはいいね!Gemini API最高。Open AIよりシンプルなコードでやりたいことができて、生産性が爆上がりした。

忘れないようにメモを残そうと思います。

実行コード

Google Colaboratoryで実行。最近Google Colabはコード予測をしてくれて凄く便利!仕事でも使えるといいんだけど、セキュリティの関係でアクセスできないんだよな。 

!pip install -q -U google-generativeai
# Import the Python SDK
import google.generativeai as genai
# Used to securely store your API key
from google.colab import userdata

GOOGLE_API_KEY=userdata.get('GOOGLE_GEMINI_API')
genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel('gemini-pro')

学んだ英単語を入れると、英語の例文と日本語の和訳を出力してくれる関数を作成。

def translation(word):
    response = model.generate_content(f"Tell me a sentence using {word}.\
    and add translation to Japanese")
    return response.text

SUITで学んだ新しい英語をlearned_wordsのリストに入力。
単語を辞書のKeyに、英文/和文を辞書のValueに出力。

learned_words = ["eloquent", "persuasive", "indebted", "plead", "in on it", "despise",\
                 "throw someone under the bus"]

examples = {}

for word in learned_words:
    examples[word] = translation(word)

辞書に保存された結果。一気に出力できてめちゃ便利!

{'eloquent': 'Her speech was so eloquent that it moved the audience to tears.\n彼女のスピーチは非常に雄弁だったので、観客は感動して涙を流した。',
 'persuasive': '**English:** The persuasive speaker convinced the audience to support his proposal.\n**Japanese:** 説得力のあるスピーチが、聴衆をその提案を支持するよう納得させた。',
 'indebted': '**Sentence:**\nThe students were deeply indebted to their teacher for their exceptional guidance.\n\n**Japanese Translation:**\nその生徒たちは、並外れた指導をしてくれた先生に大いに恩義を感じていた。',
 'plead': 'He pleaded not guilty to the charges.\n\n彼は告発に対して無罪を主張した。',
 'in on it': 'Look! The cat is sitting in on it.\n見なさい!猫がその上に座ってます。',
 'despise': 'I despise hypocrisy.\n私は偽善を軽蔑する。',
 'throw someone under the bus': 'He threw his friend under the bus to save his own skin.\n彼は自分の身を守るために友達を犠牲にした。'}

この記事が参加している募集

#新生活をたのしく

47,900件

この記事が気に入ったらサポートをしてみませんか?