File size: 2,147 Bytes
1afab69
6856cd2
1afab69
65b98ef
 
 
 
 
 
 
 
 
 
 
 
 
a2de492
6856cd2
 
 
 
 
65b98ef
 
 
1afab69
6856cd2
 
 
 
 
 
 
 
1afab69
65b98ef
 
 
 
 
1afab69
65b98ef
 
 
 
 
 
1afab69
65b98ef
 
 
 
 
 
1afab69
65b98ef
 
 
 
6856cd2
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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=