Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,8 +15,8 @@ def respond(
|
|
15 |
top_p,
|
16 |
frequency_penalty,
|
17 |
seed,
|
18 |
-
|
19 |
-
|
20 |
model_search_term,
|
21 |
selected_model
|
22 |
):
|
@@ -149,15 +149,7 @@ seed_slider = gr.Slider(
|
|
149 |
label="Seed (-1 for random)"
|
150 |
)
|
151 |
|
152 |
-
#
|
153 |
-
custom_model_box = gr.Textbox(
|
154 |
-
value="",
|
155 |
-
label="Custom Model",
|
156 |
-
info="(Optional) Provide a custom Hugging Face model path. Overrides any selected featured model.",
|
157 |
-
placeholder="meta-llama/Llama-3.3-70B-Instruct"
|
158 |
-
)
|
159 |
-
|
160 |
-
# Provider selection
|
161 |
providers_list = [
|
162 |
"hf-inference", # Default Hugging Face Inference
|
163 |
"cerebras", # Cerebras provider
|
@@ -171,6 +163,7 @@ providers_list = [
|
|
171 |
"openai" # OpenAI compatible endpoints
|
172 |
]
|
173 |
|
|
|
174 |
provider_radio = gr.Radio(
|
175 |
choices=providers_list,
|
176 |
value="hf-inference",
|
@@ -178,6 +171,31 @@ provider_radio = gr.Radio(
|
|
178 |
info="Select which inference provider to use. Uses your Hugging Face PRO credits."
|
179 |
)
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
# Model selection components
|
182 |
model_search_box = gr.Textbox(
|
183 |
label="Filter Models",
|
@@ -237,43 +255,162 @@ def set_custom_model_from_radio(selected):
|
|
237 |
print(f"Featured model selected: {selected}")
|
238 |
return selected
|
239 |
|
240 |
-
#
|
241 |
-
|
242 |
-
|
243 |
-
additional_inputs=[
|
244 |
-
system_message_box,
|
245 |
-
max_tokens_slider,
|
246 |
-
temperature_slider,
|
247 |
-
top_p_slider,
|
248 |
-
frequency_penalty_slider,
|
249 |
-
seed_slider,
|
250 |
-
provider_radio, # Provider selection (moved up)
|
251 |
-
custom_model_box, # Custom Model (moved down)
|
252 |
-
model_search_box, # Model search box
|
253 |
-
featured_model_radio # Featured model radio
|
254 |
-
],
|
255 |
-
fill_height=True,
|
256 |
-
chatbot=chatbot,
|
257 |
-
theme="Nymbo/Nymbo_Theme",
|
258 |
-
)
|
259 |
-
print("ChatInterface object created.")
|
260 |
|
261 |
-
with
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
model_search_box.change(
|
264 |
fn=filter_models,
|
265 |
inputs=model_search_box,
|
266 |
outputs=featured_model_radio
|
267 |
)
|
268 |
-
|
269 |
-
|
270 |
-
# Connect the featured model radio to update the custom model box
|
271 |
featured_model_radio.change(
|
272 |
fn=set_custom_model_from_radio,
|
273 |
inputs=featured_model_radio,
|
274 |
outputs=custom_model_box
|
275 |
)
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
print("Gradio interface initialized.")
|
279 |
|
|
|
15 |
top_p,
|
16 |
frequency_penalty,
|
17 |
seed,
|
18 |
+
provider, # Provider selection (moved up)
|
19 |
+
custom_model, # Custom Model (moved down)
|
20 |
model_search_term,
|
21 |
selected_model
|
22 |
):
|
|
|
149 |
label="Seed (-1 for random)"
|
150 |
)
|
151 |
|
152 |
+
# Provider selection with model links
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
providers_list = [
|
154 |
"hf-inference", # Default Hugging Face Inference
|
155 |
"cerebras", # Cerebras provider
|
|
|
163 |
"openai" # OpenAI compatible endpoints
|
164 |
]
|
165 |
|
166 |
+
# Define provider selection with markdown links
|
167 |
provider_radio = gr.Radio(
|
168 |
choices=providers_list,
|
169 |
value="hf-inference",
|
|
|
171 |
info="Select which inference provider to use. Uses your Hugging Face PRO credits."
|
172 |
)
|
173 |
|
174 |
+
# Create markdown links for each provider
|
175 |
+
provider_links = {
|
176 |
+
"hf-inference": "View all models hosted by [Hugging Face](https://huggingface.co/models?inference_provider=hf-inference&pipeline_tag=text-generation&sort=trending)",
|
177 |
+
"cerebras": "View all models hosted by [Cerebras](https://huggingface.co/models?inference_provider=cerebras&pipeline_tag=text-generation&sort=trending)",
|
178 |
+
"together": "View all models hosted by [Together AI](https://huggingface.co/models?inference_provider=together&pipeline_tag=text-generation&sort=trending)",
|
179 |
+
"sambanova": "View all models hosted by [SambaNova](https://huggingface.co/models?inference_provider=sambanova&pipeline_tag=text-generation&sort=trending)",
|
180 |
+
"novita": "View all models hosted by [Novita AI](https://huggingface.co/models?inference_provider=novita&pipeline_tag=text-generation&sort=trending)",
|
181 |
+
"cohere": "View all models hosted by [Cohere](https://huggingface.co/models?inference_provider=cohere&pipeline_tag=text-generation&sort=trending)",
|
182 |
+
"fireworks-ai": "View all models hosted by [Fireworks AI](https://huggingface.co/models?inference_provider=fireworks-ai&pipeline_tag=text-generation&sort=trending)",
|
183 |
+
"hyperbolic": "View all models hosted by [Hyperbolic](https://huggingface.co/models?inference_provider=hyperbolic&pipeline_tag=text-generation&sort=trending)",
|
184 |
+
"nebius": "View all models hosted by [Nebius](https://huggingface.co/models?inference_provider=nebius&pipeline_tag=text-generation&sort=trending)",
|
185 |
+
"openai": "View all models hosted by [OpenAI compatible endpoints](https://huggingface.co/models?inference_provider=openai&pipeline_tag=text-generation&sort=trending)",
|
186 |
+
}
|
187 |
+
|
188 |
+
# Provider links markdown
|
189 |
+
provider_links_md = gr.Markdown(provider_links["hf-inference"])
|
190 |
+
|
191 |
+
# Custom model box (moved down)
|
192 |
+
custom_model_box = gr.Textbox(
|
193 |
+
value="",
|
194 |
+
label="Custom Model",
|
195 |
+
info="(Optional) Provide a custom Hugging Face model path. Overrides any selected featured model.",
|
196 |
+
placeholder="meta-llama/Llama-3.3-70B-Instruct"
|
197 |
+
)
|
198 |
+
|
199 |
# Model selection components
|
200 |
model_search_box = gr.Textbox(
|
201 |
label="Filter Models",
|
|
|
255 |
print(f"Featured model selected: {selected}")
|
256 |
return selected
|
257 |
|
258 |
+
# Update provider links when provider selection changes
|
259 |
+
def update_provider_info(provider):
|
260 |
+
return provider_links[provider]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
262 |
+
# Custom layout with Blocks
|
263 |
+
with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
|
264 |
+
chatbot_ui = gr.Chatbot(height=600, show_copy_button=True, placeholder="Select a model and begin chatting", layout="panel")
|
265 |
+
|
266 |
+
with gr.Row():
|
267 |
+
with gr.Column():
|
268 |
+
msg = gr.Textbox(
|
269 |
+
scale=4,
|
270 |
+
show_label=False,
|
271 |
+
placeholder="Enter text and press enter",
|
272 |
+
container=False,
|
273 |
+
)
|
274 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
275 |
+
|
276 |
+
with gr.Accordion("Additional Inputs", open=False):
|
277 |
+
system_message_box = gr.Textbox(value="", placeholder="You are a helpful assistant.", label="System Prompt")
|
278 |
+
|
279 |
+
with gr.Row():
|
280 |
+
with gr.Column():
|
281 |
+
max_tokens_slider = gr.Slider(
|
282 |
+
minimum=1,
|
283 |
+
maximum=4096,
|
284 |
+
value=512,
|
285 |
+
step=1,
|
286 |
+
label="Max tokens"
|
287 |
+
)
|
288 |
+
temperature_slider = gr.Slider(
|
289 |
+
minimum=0.1,
|
290 |
+
maximum=4.0,
|
291 |
+
value=0.7,
|
292 |
+
step=0.1,
|
293 |
+
label="Temperature"
|
294 |
+
)
|
295 |
+
top_p_slider = gr.Slider(
|
296 |
+
minimum=0.1,
|
297 |
+
maximum=1.0,
|
298 |
+
value=0.95,
|
299 |
+
step=0.05,
|
300 |
+
label="Top-P"
|
301 |
+
)
|
302 |
+
|
303 |
+
with gr.Column():
|
304 |
+
frequency_penalty_slider = gr.Slider(
|
305 |
+
minimum=-2.0,
|
306 |
+
maximum=2.0,
|
307 |
+
value=0.0,
|
308 |
+
step=0.1,
|
309 |
+
label="Frequency Penalty"
|
310 |
+
)
|
311 |
+
seed_slider = gr.Slider(
|
312 |
+
minimum=-1,
|
313 |
+
maximum=65535,
|
314 |
+
value=-1,
|
315 |
+
step=1,
|
316 |
+
label="Seed (-1 for random)"
|
317 |
+
)
|
318 |
+
|
319 |
+
# Provider selection section with markdown links
|
320 |
+
with gr.Group():
|
321 |
+
provider_radio = gr.Radio(
|
322 |
+
choices=providers_list,
|
323 |
+
value="hf-inference",
|
324 |
+
label="Inference Provider",
|
325 |
+
info="Select which inference provider to use. Uses your Hugging Face PRO credits."
|
326 |
+
)
|
327 |
+
provider_links_md = gr.Markdown(provider_links["hf-inference"])
|
328 |
+
|
329 |
+
# Connect provider radio to update markdown links
|
330 |
+
provider_radio.change(
|
331 |
+
fn=update_provider_info,
|
332 |
+
inputs=provider_radio,
|
333 |
+
outputs=provider_links_md
|
334 |
+
)
|
335 |
+
|
336 |
+
# Custom model box (moved below provider selection)
|
337 |
+
custom_model_box = gr.Textbox(
|
338 |
+
value="",
|
339 |
+
label="Custom Model",
|
340 |
+
info="(Optional) Provide a custom Hugging Face model path. Overrides any selected featured model.",
|
341 |
+
placeholder="meta-llama/Llama-3.3-70B-Instruct"
|
342 |
+
)
|
343 |
+
|
344 |
+
# Model filter and selection
|
345 |
+
model_search_box = gr.Textbox(
|
346 |
+
label="Filter Models",
|
347 |
+
placeholder="Search for a featured model...",
|
348 |
+
lines=1
|
349 |
+
)
|
350 |
+
|
351 |
+
featured_model_radio = gr.Radio(
|
352 |
+
label="Select a model below",
|
353 |
+
choices=models_list,
|
354 |
+
value="meta-llama/Llama-3.3-70B-Instruct",
|
355 |
+
interactive=True
|
356 |
+
)
|
357 |
+
|
358 |
+
# Connect model filter and selection events
|
359 |
model_search_box.change(
|
360 |
fn=filter_models,
|
361 |
inputs=model_search_box,
|
362 |
outputs=featured_model_radio
|
363 |
)
|
364 |
+
|
|
|
|
|
365 |
featured_model_radio.change(
|
366 |
fn=set_custom_model_from_radio,
|
367 |
inputs=featured_model_radio,
|
368 |
outputs=custom_model_box
|
369 |
)
|
370 |
+
|
371 |
+
# Chat history state
|
372 |
+
history_state = gr.State([])
|
373 |
+
|
374 |
+
# Connect chat functionality
|
375 |
+
submit_btn.click(
|
376 |
+
fn=respond,
|
377 |
+
inputs=[
|
378 |
+
msg,
|
379 |
+
history_state,
|
380 |
+
system_message_box,
|
381 |
+
max_tokens_slider,
|
382 |
+
temperature_slider,
|
383 |
+
top_p_slider,
|
384 |
+
frequency_penalty_slider,
|
385 |
+
seed_slider,
|
386 |
+
provider_radio, # Provider selection (moved up)
|
387 |
+
custom_model_box, # Custom Model (moved down)
|
388 |
+
model_search_box,
|
389 |
+
featured_model_radio
|
390 |
+
],
|
391 |
+
outputs=[chatbot_ui, history_state],
|
392 |
+
show_progress=True,
|
393 |
+
)
|
394 |
+
|
395 |
+
msg.submit(
|
396 |
+
fn=respond,
|
397 |
+
inputs=[
|
398 |
+
msg,
|
399 |
+
history_state,
|
400 |
+
system_message_box,
|
401 |
+
max_tokens_slider,
|
402 |
+
temperature_slider,
|
403 |
+
top_p_slider,
|
404 |
+
frequency_penalty_slider,
|
405 |
+
seed_slider,
|
406 |
+
provider_radio, # Provider selection (moved up)
|
407 |
+
custom_model_box, # Custom Model (moved down)
|
408 |
+
model_search_box,
|
409 |
+
featured_model_radio
|
410 |
+
],
|
411 |
+
outputs=[chatbot_ui, history_state],
|
412 |
+
show_progress=True,
|
413 |
+
)
|
414 |
|
415 |
print("Gradio interface initialized.")
|
416 |
|