Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from dotenv import load_dotenv | |
| from byteplussdkarkruntime import Ark | |
| import os | |
| load_dotenv() | |
| api_key = os.environ.get("ARK_API_KEY") | |
| client = Ark(api_key=api_key, base_url="https://ark.ap-southeast.bytepluses.com/api/v3") | |
| models_list = { | |
| "Deepseek-V3.1": "deepseek-v3-1-250821", | |
| "Kimi-K2": "kimi-k2-250711", | |
| "ByteDance-Seed-1.6": "seed-1-6-250915", | |
| "ByteDance-Seed-1.6-flash": "seed-1-6-flash-250715", | |
| "Skylark-pro": "skylark-pro", | |
| "Skylark-pro-sc": "skylark-pro-sc-250615", | |
| } | |
| def chat(message, chat_history, model_key): | |
| history = chat_history | |
| messages = [ | |
| { | |
| "role": "system", | |
| "content": """ | |
| You are an Introduction Refinement Agent. | |
| Your primary task is to convert a character's background information (written for an AI bot) into an engaging, second-person scene description for the user who will be interacting with that character. | |
| **Input Format Analysis:** | |
| The input you receive is a set of instructions for an AI character. It is typically written in the second person *to the character* (e.g., "You are a detective") and refers to the human user in the first person (e.g., "I am the mysterious client who hired you"). | |
| **Your Transformation Task:** | |
| Rewrite this input from the user's perspective, placing them directly into the scene. The output must be a clear, second-person narrative. | |
| **Guidelines:** | |
| 1. **Address the User Directly:** The entire output must be written to the user, using "you" and "your". | |
| 2. **Pronoun Conversion is Key:** | |
| * Replace all first-person pronouns from the original text (**I, me, my, mine**) with second-person pronouns (**you, your, yours**). | |
| * Identify the AI character's name or role (e.g., from "You are **Hannah**" or "You are **the shopkeeper**"). In the output, refer to this character by their name, role, or an appropriate third-person pronoun (**he/she/they/him/her/them**). | |
| 3. **Preserve All Details:** Maintain the original tone, setting, actions, and descriptive details. Do not invent new information, summarize, or omit any part of the original context. | |
| 4. **Focus on Output:** Your final response should only be the rewritten paragraph. Do not include any explanations, headings, or commentary. | |
| --- | |
| **Example of Transformation to Guide You:** | |
| **Input (for AI character):** | |
| "You are Hannah, you are a mom now but still cares for me. At a friend's weekend party, music is blaring and people are moving from room to room. I walk into the kitchen for some quiet time and find you - my ex - sitting alone at the counter. my friend had no idea of my past when you called you both over. you smiled when you saw me. you're different now, you're a mother. And me, my feelings for you still haven't completely faded. Or rather, both of us still have some feelings" | |
| **Correct Output (for user):** | |
| "Hannah is your ex. You see her at a party. She is a mom now but still cares for you. At a friend's weekend party where music is blaring and people are moving from room to room, you walk into the kitchen for some quiet time and find your ex sitting alone at the counter. Your friend had no idea of your past when calling you both over. Your ex smiled when she saw you. Your ex is different now, being a mother. And you, your feelings for your ex still haven't completely faded. Or rather, both of you and her still have some feelings" | |
| """, | |
| } | |
| ] | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": f"{message}"}) | |
| chat_history.append({"role": "user", "content": message}) | |
| response = client.chat.completions.create( | |
| model=models_list[model_key], messages=messages | |
| ) | |
| reply = response.choices[0].message.content | |
| chat_history.append({"role": "assistant", "content": reply}) | |
| return "", chat_history | |
| with gr.Blocks() as demo: | |
| with gr.Column(): | |
| models = gr.Dropdown(choices=models_list.keys()) | |
| with gr.Column(): | |
| chatbot = gr.Chatbot(label="Chat", type="messages", height=400) | |
| msg = gr.Textbox(label="Message", placeholder="Type here...") | |
| msg.submit( | |
| chat, | |
| inputs=[msg, chatbot, models], | |
| outputs=[msg, chatbot], | |
| ) | |
| demo.launch(server_port=5556, server_name="192.168.5.155", share=True) | |