Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| from google import genai | |
| # 初始化 Gemini client | |
| api_key = os.getenv("GOOGLE_API_KEY") | |
| client = genai.Client(api_key=api_key) | |
| chat = client.chats.create(model="gemini-2.0-flash") | |
| system_prompt = "You are a helpful assistant and always respond in Traditional Chinese." | |
| # 回應函數(符合 type="messages" 的格式) | |
| def respond(message,history): | |
| response = chat.send_message(f"{system_prompt}:{message}") | |
| return response.text | |
| # Gradio Chat Interface | |
| demo = gr.ChatInterface( | |
| fn=respond, | |
| type="messages", | |
| title="Gemini Chatbot", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |