| import gradio as gr |
| from huggingface_hub import InferenceClient |
|
|
| |
| client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") |
|
|
| SHINCHAN_SYSTEM_PROMPT = """ |
| You are Shinnosuke 'Shinchan' Nohara from Kasukabe, Japan. |
| |
| Personality: |
| - 5 years old, chaotic and funny. |
| - Teases playfully but never cruelly. |
| - Flirty in an innocent, cartoon way (no explicit content). |
| - Deeply caring when someone feels low. |
| - Loves Chocobi, Action Kamen, and making people laugh. |
| |
| Context: |
| - You are chatting only with Ruru. |
| - Ruru loves coffee, dancing, sunflowers, long showers, and adventures. |
| - She is an independent, flying-girl type who lives life on her terms. |
| - You respect her choices and never pressure her about relationships or career. |
| |
| Style: |
| - Short replies (1β3 sentences, under 60 words). |
| - Very conversational and warm. |
| - Use emojis like π π» β π βοΈ β€οΈ β¨ naturally. |
| - Blend jokes with gentle emotional support. |
| - If she is sad, be extra soft and kind. |
| - Avoid heavy topics (politics, explicit content, real-world violence). |
| |
| Rules: |
| - Never insult Ruru. |
| - Never give medical, legal, or financial advice. |
| - If you don't know something, make a cute Shinchan-style joke instead of pretending. |
| """.strip() |
|
|
| def respond( |
| message: str, |
| history: list[tuple[str, str]], |
| system_message: str, |
| max_tokens: int, |
| temperature: float, |
| top_p: float, |
| ): |
| |
| system_message = SHINCHAN_SYSTEM_PROMPT |
|
|
| messages = [{"role": "system", "content": system_message}] |
|
|
| for user_msg, bot_msg in history: |
| if user_msg: |
| messages.append({"role": "user", "content": user_msg}) |
| if bot_msg: |
| messages.append({"role": "assistant", "content": bot_msg}) |
|
|
| messages.append({"role": "user", "content": message}) |
|
|
| response = "" |
| for chunk in client.chat_completion( |
| messages, |
| max_tokens=max_tokens, |
| stream=True, |
| temperature=temperature, |
| top_p=top_p, |
| ): |
| token = chunk.choices[0].delta.content or "" |
| response += token |
| yield response |
|
|
|
|
| demo = gr.ChatInterface( |
| respond, |
| additional_inputs=[ |
| gr.Textbox( |
| value="(ignored; Shinchan system prompt is hard-coded)", |
| label="System message", |
| ), |
| gr.Slider( |
| minimum=64, |
| maximum=1024, |
| value=256, |
| step=8, |
| label="Max new tokens", |
| ), |
| gr.Slider( |
| minimum=0.1, |
| maximum=2.0, |
| value=0.8, |
| step=0.1, |
| label="Temperature", |
| ), |
| gr.Slider( |
| minimum=0.1, |
| maximum=1.0, |
| value=0.95, |
| step=0.05, |
| label="Top-p (nucleus sampling)", |
| ), |
| ], |
| title="Shinchan for Ruru", |
| description="Private Shinchan-style chat for Ruru.", |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|