Spaces:
Sleeping
Sleeping
Delete gemini_simple.py
Browse files- gemini_simple.py +0 -30
gemini_simple.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
| 1 |
-
# === Gemini Chatbot ===
|
| 2 |
-
# 這是一個簡單的 Gemini 聊天機器人範例,使用 Gradio 建立聊天介面
|
| 3 |
-
# 這個範例使用 Google 的 Gemini API,請確保你已經安裝了 google-genai 套件
|
| 4 |
-
# 並且在環境變數中設置了 GOOGLE_API_KEY
|
| 5 |
-
# https://googleapis.github.io/python-genai/index.html
|
| 6 |
-
|
| 7 |
-
import os
|
| 8 |
-
import gradio as gr
|
| 9 |
-
from google import genai
|
| 10 |
-
|
| 11 |
-
# 初始化 Gemini client
|
| 12 |
-
api_key = os.getenv("GOOGLE_API_KEY")
|
| 13 |
-
client = genai.Client(api_key=api_key)
|
| 14 |
-
chat = client.chats.create(model="gemini-2.0-flash")
|
| 15 |
-
system_prompt = "You are a helpful assistant and always respond in Traditional Chinese."
|
| 16 |
-
|
| 17 |
-
# 回應函數(符合 type="messages"的格式)
|
| 18 |
-
def respond(message,history):
|
| 19 |
-
response = chat.send_message(f"{system_prompt}:{message}")
|
| 20 |
-
return response.text
|
| 21 |
-
|
| 22 |
-
# Gradio Chat Interface
|
| 23 |
-
demo = gr.ChatInterface(
|
| 24 |
-
fn=respond,
|
| 25 |
-
type="messages",
|
| 26 |
-
title="B09000000 黃老師",
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
if __name__ == "__main__":
|
| 30 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|