gemini api 应用

安装

gemini

Prerequisites
To complete this quickstart locally, ensure that your development environment meets the following requirements:

Python 3.9+
An installation of jupyter to run the notebook.

Install the Gemini API SDK
The Python SDK for the Gemini API is contained in the google-generativeai package. Install the dependency using pip:

pip install -q -U google-generativeai

注意:使用美国节点成功率更高
获取key
gemini 官方入门教程
在这里插入图片描述

import google.generativeai as genai
import os
genai.configure(api_key='你的key')
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content("Write a story about an AI and magic")
print(response.text)

在这里插入图片描述

gradio

gradio 官方入门教程
Prerequisite: Gradio requires Python 3.8 or higher.

We recommend installing Gradio using pip, which is included by default in Python. Run this in your terminal or command prompt:

pip install gradio

运行代码

import gradio as gr
import google.generativeai as genai
import os

genai.configure(api_key='你自己的key')
model = genai.GenerativeModel('gemini-1.5-flash')

def yes_man(message, history):
    response = model.generate_content(message)
    print(response.text)
    return response.text

gr.ChatInterface(
    yes_man,
    chatbot=gr.Chatbot(height=600,placeholder="<strong>Your Personal Yes-Man</strong><br>Ask Me Anything"),
    textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
    title="",
    description=" EmpathyVerse",
    theme="soft",
    #examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
    cache_examples=True,
    retry_btn=None,
    undo_btn="Delete Previous",
    clear_btn="Clear",
).launch()

在这里插入图片描述

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值