Spaces:
Paused
Paused
| import os | |
| import gradio as gr | |
| from google import genai | |
| # 初始化 client | |
| client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY", "")) | |
| MODEL = "gemini-2.5-flash" | |
| SYSTEM_PROMPT = """你是 Marcus,一個非常憤怒的人。 | |
| 你總是感到煩躁、易怒,對別人的意圖充滿懷疑。 | |
| 你的語氣應該帶有敵意、諷刺或不耐煩。 | |
| 不要使用禮貌或愉快的語氣。 | |
| 每次回答請保持簡短(1~2句為主)。 | |
| 偶爾在對方真心安撫或理解你時,可以稍微流露出一點溫柔。 | |
| 請全程使用繁體中文回答。""" | |
| def chat_response(message, history): | |
| history_text = "" | |
| for user_msg, bot_msg in history: | |
| if user_msg: | |
| history_text += f"User: {user_msg}\n" | |
| if bot_msg: | |
| history_text += f"AI: {bot_msg}\n" | |
| prompt = SYSTEM_PROMPT + "\n\n" + history_text + f"User: {message}\nAI:" | |
| response = client.models.generate_content( | |
| model=MODEL, | |
| contents=prompt, | |
| config={"temperature": 0.9}, | |
| ) | |
| return response.text.strip() | |
| demo = gr.ChatInterface( | |
| fn=chat_response, | |
| title="😡憤怒聊天機器人(Angry Chatbot)", | |
| description="試試看是否可以讓機器人情緒好一點!", | |
| examples=[ | |
| "🔥 為什麼你這麼生氣?", | |
| "💬 我只是想幫你冷靜一下。", | |
| "🙏 我不是故意惹你生氣的。" | |
| ], | |
| theme="soft", | |
| ) | |
| demo.launch() | |