Google的Gemini 2.0 Pro:深入深入了解多模式AI功能和部署
Google已揭露了Gemini 2.0 Pro,這是其最先進的AI模型。 目前處於實驗階段,開發人員的訪問是通過API訪問。 這個強大的模型在編碼和復雜的推理方面閃耀,擁有200萬個令牌上下文窗口,用於處理廣泛的信息。 它利用Google搜索和執行代碼的能力增加了其多功能性。>
>本教程演示瞭如何使用Google的genai python軟件包訪問Gemini 2.0 Pro的功能,構建用戶友好的Gradio應用程序,並將其部署到擁抱面部空間以供公共訪問。 有關針對OpenAI和DeepSeek模型的比較分析,請參見我們關於Gemini 2.0 Flash Thinking實驗的指南。 阿德爾·尼姆(Adel Nehme)的教程提供了進一步的見解,以使用雙子座2.0:構建多模式應用程序。
設置GEMINI 2.0 Pro
訪問Google AI Studio網站並登錄。
來源:Google AI Studio
>環境變量:
python軟件包安裝:GEMINI_API_KEY
安裝所需的軟件包:
探索雙子座2.0 Pro功能
pip install google-genai gradio
import os from google import genai API_KEY = os.environ.get("GEMINI_API_KEY") client = genai.Client(api_key=API_KEY) response = client.models.generate_content_stream( model="gemini-2.0-pro-exp-02-05", contents=["Explain how the Stock Market works"]) for chunk in response: print(chunk.text, end="")
from google import genai from google.genai import types import PIL.Image image = PIL.Image.open('image.png') response = client.models.generate_content_stream( model="gemini-2.0-pro-exp-02-05", contents=["Describe this image", image]) for chunk in response: print(chunk.text, end="")
with open('audio.wav', 'rb') as f: audio_bytes = f.read() response = client.models.generate_content_stream( model='gemini-2.0-pro-exp-02-05', contents=[ 'Describe this audio', types.Part.from_bytes( data=audio_bytes, mime_type='audio/wav', ) ] ) for chunk in response: print(chunk.text, end="")
from google import genai from google.genai import types import pathlib prompt = "Summarize this document" response = client.models.generate_content_stream( model="gemini-2.0-pro-exp-02-05", contents=[ types.Part.from_bytes( data=pathlib.Path('cv.pdf').read_bytes(), mime_type='application/pdf', ), prompt]) for chunk in response: print(chunk.text, end="")
構建和部署Gradio應用程序>
提供的GitHub存儲庫(Gemini-2-Pro-Chat)包含Gradio應用程序代碼。 克隆和設置環境後,本地運行。 部署到擁抱面積的空間涉及創建一個新的空間,克隆存儲庫,添加> file(包含),按照指示進行修改
並推動更改。 切記在擁抱的面部空間設置中添加您的作為秘密。 python app.py
>
requirements.txt
google-genai==1.0.0
結論README.md
GEMINI_API_KEY
以上是使用Gemini 2.0 Pro構建多模式AI應用程序的詳細內容。更多資訊請關注PHP中文網其他相關文章!