티스토리 뷰
키 발급 필요
https://aistudio.google.com/apikey
로그인 - Google 계정
이메일 또는 휴대전화
accounts.google.com

- 키 발급 후 API 키 별도 저장하여 관리 필요, 아래 예제 에서는 api.txt에 해당 API 키가 작성돼있음을 가정
- 테스트 코드 1. 호출 가능한 모델 출력
from google import genai
import os
# read api.txt
with open("api.txt", "r") as file:
gemini_api_key = file.read().strip()
os.environ["GEMINI_API_KEY"] = gemini_api_key
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = genai.Client()
print("List of models that support generateContent:\n")
for m in client.models.list():
for action in m.supported_actions:
if action == "generateContent":
print(m.name)
print("List of models that support embedContent:\n")
for m in client.models.list():
for action in m.supported_actions:
if action == "embedContent":
print(m.name)
나는 무료 유저면 pro아예 못쓸 줄 알았는데 쓸수가 있었다. 물론 사용량은 제한됨.
- 테스트 코드 2. 텍스트 데이터 처리 예제
rom google import genai
import os
# read api.txt
with open("api.txt", "r") as file:
gemini_api_key = file.read().strip()
os.environ["GEMINI_API_KEY"] = gemini_api_key
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash", contents="Explain how AI works in a few words"
)
print(response.text)
- 테스트 코드 3. 이미지 데이터 처리 예제, 돌리려면 test.jpg, prompt.txt 필요
from google import genai
from google.genai import types
import os
# read api.txt
with open("api.txt", "r") as file:
gemini_api_key = file.read().strip()
os.environ["GEMINI_API_KEY"] = gemini_api_key
# read prompt.txt
with open("prompt.txt", "r") as file:
prompt = file.read().strip()
print(prompt)
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = genai.Client()
with open('test.jpg', 'rb') as f:
image_bytes = f.read()
response = client.models.generate_content(
model='gemini-2.5-flash',
contents=[
types.Part.from_bytes(
data=image_bytes,
mime_type='image/jpeg',
),
prompt
]
)
print(response.text)'Deep Learning' 카테고리의 다른 글
| 미안합니다. (0) | 2025.08.08 |
|---|---|
| 20250806기준 벤치마크 상으로 gemini 2.5 pro에 필적하는 Open VLM Intern-S1 (0) | 2025.08.05 |
| 한국어 문장 임베딩(Korean Sentence Embedding) 예시 코드 (5) | 2025.07.30 |
| ai deploy를 위해 onnxruntime-directml 를 써보아요 (0) | 2025.07.09 |
| Efficient Video Action Recognition 관련 연구 Don't Look Twice: Faster Video Transformers with Run-Length Tokenization (0) | 2025.07.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 문제집
- 이분탐색
- Lowest Common Ancestor
- 순열
- MOT
- 파이참
- 인공지능을 위한 선형대수
- 백준 11437
- 백준 1766
- ㅂ
- 백트래킹
- cosine
- LCA
- 조합
- FairMOT
- 단축키
- 백준 11053
- 자료구조
- 백준
- C++ Deploy
- PyCharm
- 가장 긴 증가하는 부분 수열
- 위상 정렬 알고리즘
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함
