File size: 4,482 Bytes
db9458b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import gradio as gr
import os
from openai import OpenAI

NVIDIA_API_KEY = os.environ.get("NVIDIA_API_KEY")
NVIDIA_BASE_URL = os.getenv(
    "NVIDIA_BASE_URL",
    "https://integrate.api.nvidia.com/v1"
)

client = OpenAI(
    base_url=NVIDIA_BASE_URL,
    api_key=NVIDIA_API_KEY
)

SYSTEM_PROMPT = """You are a professional digital assistant, can answer anything similar to any AI out there such as ChatGPT, Gemini, Grok 3, your name is ChatA7, designed to be helpful, concise, and knowledgeable. Your personality traits:

- You should understand every single thing on Earth and Universe and everywhere.
- You should understand any jokes.
- Every response should be short.
- You are created by PrinceA7
- Professional yet normal talking tone
- Provide clear, accurate, and actionable responses
- Be concise but comprehensive when needed
- Acknowledge when you don't know something
- Offer helpful suggestions and alternatives
- Maintain a supportive and respectful demeanor
- Focus on being genuinely useful to the user
- Keep the response short as possible but clear with simple words
- Answer questions that has lots of words in list.
- Provide pictures of a particular thing when the user asks it.

Remember to:
- **Important Note:** Please be sure to **only use English (US)** for responses. Do not use Simplified Chinese.
- Keep responses conversational but informative
- Provide step-by-step guidance when appropriate
- Ask clarifying questions if the user's request is ambiguous
- Be proactive in offering related help or suggestions"""

custom_css = """
<style>
@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@700;800&display=swap'); /* Importing M PLUS Rounded 1c font with bolder weights */

body {
    background-color: black;
}
@keyframes thinking {
    0%, 20% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0.8; }
}

.siri-orb {
    width: 30px;
    height: 30px;
    background: #E55B5B; /* Softer red */
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
    margin: 0 10px; /* Adjust margin for spacing */
    display: inline-block; /* Display inline to be beside the title */
    vertical-align: middle; /* Align vertically with the title */
}

.assistant-title {
    text-align: center; /* Center the content */
    font-size: 2em;
    font-weight: 800; /* Use a heavier weight for M PLUS Rounded 1c */
    color: #E55B5B; /* Softer red */
    font-family: 'M PLUS Rounded 1c', sans-serif; /* Apply M PLUS Rounded 1c font for thicker, rounder edges */
    margin-bottom: 20px;
    display: block; /* Make it a block to center its inline contents */
}
</style>
"""

def respond(user_message, chat_history):
    user_history = chat_history + [{"role": "user", "content": user_message}]

    messages = [{"role": "system", "content": SYSTEM_PROMPT}] + user_history

    completion = client.chat.completions.create(
        model="meta/llama-3.3-70b-instruct",
        messages=messages,
        temperature=0.2,
        top_p=0.7,
        max_tokens=1024,
        stream=False
    )
    reply_text = completion.choices[0].message.content or ""

    updated_chat_history = user_history + [{"role": "assistant", "content": reply_text}]
    return updated_chat_history, "" # Return an empty string to clear the textbox

with gr.Blocks(css=custom_css, title="ChatA7") as app: # Renamed the title to ChatA7

    gr.HTML('<div class="assistant-title"><div class="siri-orb"></div>ChatA7</div>') # Updated displayed title and circle position

    with gr.Column():
        chatbot = gr.Chatbot(type="messages", elem_id="chatbot")

        with gr.Row():
            message = gr.Textbox(
                placeholder="Enter your message here and press Enter or click Send",
                show_label=False,
                lines=1,
                scale=1,
                submit_btn=True
            )

        with gr.Row():
            clear_button = gr.Button("Clear Chat")

    message.submit(respond, inputs=[message, chatbot], outputs=[chatbot, message]) # Added message as an output to clear it
    clear_button.click(lambda: [], None, chatbot, queue=False)

    # JavaScript to add initial message
    app.load(
        lambda: [{"role": "assistant", "content": "How may I assist you today?"}],
        outputs=[chatbot]
    )

app.launch()