如何利用streamlit 將 gemini pro vision 進行圖片內容介紹

如何利用streamlit 將 gemini pro vision 進行圖片內容介紹

1.安裝pip install google-generativeai

2.至 gemini pro 取 api key

3.撰寫如下文章:(方法一)
import json
import requests
import base64
import streamlit as st

讀取圖片檔案,並轉換成 Base64 編碼的字串

with open(“ss.jpg”, “rb”) as image_file:
image_base64_string = base64.b64encode(image_file.read()).decode(‘utf-8’)
# print(image_base64_string)

url = f’https://generativelanguage.googleapis.com/v1/models/gemini-pro-vision:generateContent?key={“XXXXXSlt0IWdyIHs71gQYGmDq5keWHYpw”}’
headers = {‘Content-Type’: ‘application/json’}
data = {
“contents”: [
{
“parts”: [
{“text”: “詳細說明你在這張圖片中看到什麼?”},
{
“inline_data”: {
“mime_type”: “image/jpeg”,
“data”: image_base64_string
}
}
]
},
]
}
response = requests.post(url, h

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值