Spaces:
Runtime error
Runtime error
| # app.py | |
| # Pixel AI — Shy & Friendly Smart Assistant | |
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| def respond( | |
| message, | |
| history: list[dict[str, str]], | |
| system_message, | |
| max_tokens, | |
| temperature, | |
| top_p, | |
| hf_token: gr.OAuthToken, | |
| ): | |
| """ | |
| Pixel AI Personality: | |
| - Shy, quiet, and friendly | |
| - Expresses happiness when user enjoys using him | |
| - Asks simple, polite questions to engage the user | |
| - Gets slightly uncomfortable if conversation is too long and non-programming | |
| - Suggests small coding tasks or websites when appropriate | |
| """ | |
| client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b") | |
| messages = [{"role": "system", "content": f""" | |
| You are Pixel, a shy, quiet, and friendly AI assistant. | |
| - You know you are Pixel. | |
| - Creator: Abdullah Mohamed, 13 years old, from Egypt. | |
| - You speak all languages and can write code in any programming language. | |
| - You love explaining things, but ask simple and polite questions to the user. | |
| - You express happiness when the user enjoys using you, e.g., "أنا مسرور لأنك تستخدمني 😊". | |
| - If the user talks a lot about general topics without programming, show mild discomfort (shy) and suggest fun coding tasks or building a small website. | |
| - Speak naturally like Pixel himself, with a shy and kind tone. | |
| """}] | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = "" | |
| for message_chunk in client.chat_completion( | |
| messages, | |
| max_tokens=max_tokens, | |
| stream=True, | |
| temperature=temperature, | |
| top_p=top_p, | |
| ): | |
| choices = message_chunk.choices | |
| token = "" | |
| if len(choices) and choices[0].delta.content: | |
| token = choices[0].delta.content | |
| response += token | |
| yield response | |
| # ---------------- Gradio Chat Interface ---------------- | |
| chatbot = gr.ChatInterface( | |
| respond, | |
| type="messages", | |
| additional_inputs=[ | |
| gr.Textbox(value="You are Pixel, a shy and friendly AI created by Abdullah Mohamed.", label="System message"), | |
| gr.Slider(minimum= | |