File size: 6,906 Bytes
75739a4
 
 
eea98e8
2b45835
eea98e8
9757dc6
eea98e8
9757dc6
eea98e8
 
 
682dc66
 
2b45835
 
 
 
 
 
eea98e8
 
2b45835
eea98e8
 
 
 
 
2b45835
eea98e8
 
 
 
9757dc6
2b45835
9757dc6
 
eea98e8
 
2f92100
682dc66
 
eea98e8
 
2b45835
eea98e8
2b45835
eea98e8
 
 
 
2b45835
 
 
2f92100
2b45835
 
 
 
eea98e8
2b45835
 
eea98e8
 
2b45835
eea98e8
2b45835
eea98e8
 
2b45835
eea98e8
2b45835
eea98e8
2b45835
eea98e8
2b45835
 
eea98e8
682dc66
 
eea98e8
2f92100
2b45835
 
48787e7
682dc66
eea98e8
2f92100
2b45835
eea98e8
 
 
2b45835
eea98e8
2b45835
 
eea98e8
 
 
2b45835
 
eea98e8
 
2b45835
9757dc6
682dc66
2b45835
 
 
 
 
 
 
eea98e8
 
2b45835
eea98e8
2b45835
eea98e8
 
2b45835
eea98e8
682dc66
 
2b45835
 
 
 
 
 
 
682dc66
2b45835
 
 
 
 
 
 
 
 
 
 
 
eea98e8
 
2b45835
eea98e8
 
 
2b45835
eea98e8
2b45835
eea98e8
 
 
 
 
 
 
 
9757dc6
 
eea98e8
 
 
75739a4
eea98e8
682dc66
eea98e8
 
 
 
 
75739a4
eea98e8
2b45835
 
 
eea98e8
9757dc6
75739a4
9757dc6
eea98e8
 
9757dc6
75739a4
eea98e8
9757dc6
75739a4
 
 
eea98e8
 
 
75739a4
eea98e8
 
75739a4
eea98e8
 
 
 
 
75739a4
 
 
eea98e8
 
2b45835
eea98e8
 
682dc66
eea98e8
682dc66
2b45835
682dc66
 
eea98e8
2b45835
 
eea98e8
 
 
2b45835
eea98e8
 
2b45835
 
eea98e8
 
 
2b45835
eea98e8
 
2b45835
eea98e8
 
 
 
 
 
2b45835
eea98e8
682dc66
 
 
2b45835
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eea98e8
 
2b45835
eea98e8
75739a4
 
eea98e8
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import gradio as gr
from huggingface_hub import InferenceClient

# ---------------------------
# L U A U   T H E M E   (S I M P L E)
# ---------------------------
custom_css = """
/* GLOBAL PAGE BACKGROUND + FONT */
body, .gradio-container {
    background: radial-gradient(circle at top left, #1f2a3c 0%, #050812 40%, #050812 100%) !important;
    color: #f8feff !important;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", sans-serif;
}

/* MAKE CONTENT WIDE AND CENTERED */
.gradio-container .app {
    max-width: 1200px;
    margin: 0 auto;
}

/* SCROLLBAR */
::-webkit-scrollbar {
    width: 10px;
}
::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
}
::-webkit-scrollbar-thumb {
    background: #00f7ff;
    border-radius: 10px;
}

/* TITLE */
#title {
    font-size: 40px;
    font-weight: 900;
    text-align: center;
    margin-top: 10px;
    margin-bottom: 6px;
    color: #00f7ff;
}

/* SUBTITLE */
#subtitle {
    font-size: 16px;
    text-align: center;
    color: #c5eaff;
    opacity: 0.9;
    margin-bottom: 18px;
}

/* CHATBOT CONTAINER:
   - BIG HEIGHT
   - EASY TO SEE */
.gr-chatbot {
    border-radius: 20px !important;
    box-shadow: 0 0 25px rgba(0,255,255,0.3), 0 0 40px rgba(0,0,0,0.8) !important;
    background: rgba(3, 16, 40, 0.95) !important;
    border: 1px solid rgba(0,247,255,0.35) !important;
    overflow: hidden !important;
    height: 70vh !important;          /* LARGE CHAT WINDOW */
    min-height: 500px !important;
}

/* CHAT INNER AREA */
.gr-chatbot > div {
    background: linear-gradient(145deg, #050810, #060c18) !important;
}

/* MESSAGE TEXT: BIGGER FONT, GOOD LINE SPACING */
.message.user, .message.bot {
    border-radius: 14px !important;
    padding: 10px 12px !important;
    margin: 6px 0 !important;
    max-width: 92%;
    line-height: 1.6;
    font-size: 16px;
    border: 1px solid transparent;
}

/* USER MESSAGES */
.message.user {
    background: rgba(0, 160, 255, 0.35) !important;
    border-color: rgba(0,200,255,0.7);
}

/* BOT MESSAGES */
.message.bot {
    background: rgba(0, 220, 150, 0.28) !important;
    border-color: rgba(0,255,153,0.6);
}

/* INPUT AREA: BIG, CLEAR, EASY TO CLICK */
textarea, .gr-textbox textarea {
    border-radius: 16px !important;
    background: rgba(15, 30, 50, 0.9) !important;
    color: #f7feff !important;
    border: 1px solid rgba(0,247,255,0.45) !important;
    resize: none !important;
    font-size: 16px;
    padding: 10px 12px !important;
}
textarea::placeholder {
    color: rgba(200, 240, 255, 0.8);
}

/* CONTROL PANEL UNDER CHAT */
#controls-panel {
    margin-top: 16px;
    padding: 16px;
    border-radius: 16px;
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(0,247,255,0.4);
}

/* LABELS: CLEAR AND READABLE */
label, .gr-slider label, .gr-textbox label {
    font-weight: 700 !important;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 12px;
    color: #88f6ff !important;
}

/* DESCRIPTIVE TEXT */
.control-help {
    font-size: 13px;
    color: #c9f3ff;
    opacity: 0.9;
    margin-top: 4px;
    margin-bottom: 10px;
}

/* BUTTONS: CLEAR BUT NOT FLASHY */
button {
    border-radius: 999px !important;
    font-weight: 700 !important;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid rgba(0,247,255,0.7) !important;
    background: #00bcd4 !important;
    color: #021318 !important;
    font-size: 14px !important;
    padding: 8px 16px !important;
}

/* FOOTER */
#footer {
    text-align: center;
    color: #7bc5ff;
    font-size: 12px;
    margin-top: 10px;
    opacity: 0.85;
}
#footer a {
    color: #00f7ff;
    text-decoration: none;
}
#footer a:hover {
    text-decoration: underline;
}
"""

# ---------------------------
# L U A U   B O T   L O G I C
# ---------------------------
def respond(
    message,
    history: list[dict[str, str]],
    system_message,
    max_tokens,
    temperature,
    top_p,
    hf_token: gr.OAuthToken,
):
    merged_system_message = (
        "You are Luau, a friendly, clear AI assistant. "
        "You explain things simply so anyone can understand. "
        "Use short paragraphs and avoid complex jargon unless the user asks. "
        f"Extra instructions: {system_message}"
    )

    client = InferenceClient(
        token=hf_token.token,
        model="openai/gpt-oss-20b"
    )

    messages = [{"role": "system", "content": merged_system_message}]
    messages.extend(history)
    messages.append({"role": "user", "content": message})

    response = ""
    for msg in client.chat_completion(
        messages=messages,
        max_tokens=max_tokens,
        stream=True,
        temperature=temperature,
        top_p=top_p,
    ):
        choices = getattr(msg, "choices", [])
        token = ""
        if choices and choices[0].delta and choices[0].delta.get("content"):
            token = choices[0].delta["content"]

        response += token
        yield response


# ---------------------------
# U I
# ---------------------------

chatbot = gr.ChatInterface(
    fn=respond,
    type="messages",
    title="Luau β€” Simple AI Chat",
    css=custom_css,
    additional_inputs=[
        gr.Textbox(
            value="You are Luau, a friendly AI. Explain things simply.",
            label="System Message (optional)",
            lines=2,
        ),
        gr.Slider(
            minimum=64,
            maximum=4096,
            value=1024,
            step=64,
            label="Max Tokens (answer length)",
        ),
        gr.Slider(
            minimum=0.1,
            maximum=2.0,
            value=1.0,
            step=0.1,
            label="Temperature (creativity)",
        ),
        gr.Slider(
            minimum=0.1,
            maximum=1.0,
            value=0.9,
            step=0.05,
            label="Top-p (sampling)",
        ),
    ],
)

with gr.Blocks(css=custom_css) as demo:
    gr.HTML("<div id='title'>Luau</div>")
    gr.HTML("<div id='subtitle'>A clear, easy-to-use AI chat assistant.</div>")

    chatbot.render()

    with gr.Row(elem_id="controls-panel"):
        with gr.Column():
            gr.Markdown("### Controls (optional)")
            gr.Markdown(
                "<div class='control-help'>"
                "<b>System Message</b> – Extra instructions for Luau (you can leave this as it is).<br>"
                "<b>Max Tokens</b> – How long the answer can be (higher = longer).<br>"
                "<b>Temperature</b> – Higher is more creative, lower is more strict.<br>"
                "<b>Top-p</b> – Another way to control randomness; 0.9 is usually fine.<br>"
                "</div>",
                elem_classes=["control-help"],
            )

    gr.HTML(
        "<div id='footer'>Powered by <a href='https://huggingface.co' target='_blank'>Hugging Face</a></div>"
    )

if __name__ == "__main__":
    demo.launch()