Maxwell commited on
Commit
78552ec
·
verified ·
1 Parent(s): c962f9f

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +81 -9
app.py CHANGED
@@ -141,15 +141,87 @@ def respond(message, history, temperature, max_tokens):
141
  response += delta
142
  yield response
143
 
144
- demo = gr.ChatInterface(
145
- fn=respond,
146
- title="Lumen",
147
- description="by Axion Labs",
148
- additional_inputs=[
149
- gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Temperature"),
150
- gr.Slider(64, 1024, value=512, step=64, label="Max tokens"),
151
- ],
152
- additional_inputs_accordion=gr.Accordion("Settings", open=False),
 
 
 
 
 
 
 
 
 
 
153
  )
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  app = gr.mount_gradio_app(fastapi_app, demo, path="/")
 
141
  response += delta
142
  yield response
143
 
144
+ def model_status():
145
+ if llm is not None:
146
+ return "<div class='lumen-status ready'>&#9679; Model ready</div>"
147
+ return "<div class='lumen-status loading'>&#9679; Loading model&hellip; (first boot takes a few minutes)</div>"
148
+
149
+ THEME = gr.themes.Soft(
150
+ primary_hue=gr.themes.colors.violet,
151
+ secondary_hue=gr.themes.colors.indigo,
152
+ neutral_hue=gr.themes.colors.slate,
153
+ font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
154
+ font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "ui-monospace", "monospace"],
155
+ ).set(
156
+ body_background_fill="*neutral_950",
157
+ body_background_fill_dark="*neutral_950",
158
+ block_background_fill="*neutral_900",
159
+ block_background_fill_dark="*neutral_900",
160
+ block_border_width="0px",
161
+ button_primary_background_fill="linear-gradient(90deg, #7c3aed, #4f46e5)",
162
+ button_primary_background_fill_hover="linear-gradient(90deg, #8b5cf6, #6366f1)",
163
  )
164
 
165
+ CSS = """
166
+ .gradio-container { max-width: 880px !important; margin: 0 auto !important; }
167
+ #lumen-header { text-align: center; padding: 18px 0 4px; }
168
+ #lumen-header h1 {
169
+ font-size: 2.4em; font-weight: 800; margin: 0; letter-spacing: -0.02em;
170
+ background: linear-gradient(90deg, #a78bfa, #818cf8, #60a5fa);
171
+ -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
172
+ }
173
+ #lumen-header p { color: #94a3b8; margin: 4px 0 0; font-size: 0.95em; }
174
+ #lumen-header .badges { margin-top: 8px; }
175
+ #lumen-header .badge {
176
+ display: inline-block; font-size: 0.72em; padding: 3px 10px; margin: 0 3px;
177
+ border-radius: 999px; border: 1px solid #3f3f56; color: #c4b5fd; background: rgba(124,58,237,.08);
178
+ }
179
+ .lumen-status { text-align: center; font-size: 0.8em; padding: 2px 0 8px; }
180
+ .lumen-status.ready { color: #4ade80; }
181
+ .lumen-status.loading { color: #fbbf24; }
182
+ #lumen-footer { text-align: center; color: #64748b; font-size: 0.75em; padding: 10px 0 16px; }
183
+ #lumen-footer code { background: #1e1e2e; padding: 2px 6px; border-radius: 6px; color: #a5b4fc; }
184
+ footer { display: none !important; }
185
+ """
186
+
187
+ HEADER_HTML = """
188
+ <div id="lumen-header">
189
+ <h1>&#10022; Lumen</h1>
190
+ <p>A fine-tuned Llama 3.1 8B by Axion Labs</p>
191
+ <div class="badges">
192
+ <span class="badge">8B &middot; Q4_K_M</span>
193
+ <span class="badge">LoRA fine-tune</span>
194
+ <span class="badge">Free &middot; no key needed</span>
195
+ </div>
196
+ </div>
197
+ """
198
+
199
+ FOOTER_HTML = """
200
+ <div id="lumen-footer">
201
+ OpenAI-compatible API: <code>POST /v1/chat/completions</code>
202
+ &nbsp;&middot;&nbsp; works with the Axion CLI via <code>/model lumen</code>
203
+ </div>
204
+ """
205
+
206
+ with gr.Blocks(theme=THEME, css=CSS, title="Lumen — Axion Labs") as demo:
207
+ gr.HTML(HEADER_HTML)
208
+ status = gr.HTML(model_status)
209
+ gr.ChatInterface(
210
+ fn=respond,
211
+ type="messages",
212
+ examples=[
213
+ ["Who are you?"],
214
+ ["Explain how a binary search works"],
215
+ ["Write a haiku about terminals"],
216
+ ["What's the difference between TCP and UDP?"],
217
+ ],
218
+ additional_inputs=[
219
+ gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Temperature"),
220
+ gr.Slider(64, 1024, value=512, step=64, label="Max tokens"),
221
+ ],
222
+ additional_inputs_accordion=gr.Accordion("⚙️ Settings", open=False),
223
+ )
224
+ gr.HTML(FOOTER_HTML)
225
+ demo.load(model_status, outputs=status)
226
+
227
  app = gr.mount_gradio_app(fastapi_app, demo, path="/")