|
import os |
|
import gradio as gr |
|
from google import genai |
|
from google.genai import types |
|
|
|
|
|
api_key = os.getenv("GOOGLE_API_KEY") |
|
client = genai.Client(api_key=api_key) |
|
chat = client.chats.create( |
|
model="gemini-2.0-flash", |
|
config=types.GenerateContentConfig( |
|
system_instruction="You are a helpful assistant and always respond in Traditional Chinese.", |
|
temperature=0.2, |
|
max_output_tokens=256, |
|
top_p=0.8, |
|
top_k=40, |
|
), |
|
) |
|
|
|
def respond(message,history): |
|
response = chat.send_message(message) |
|
return response.text |
|
|
|
|
|
demo = gr.ChatInterface( |
|
fn=respond, |
|
type="messages", |
|
title="Gemini Chatbot", |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|