Nymbo commited on
Commit
1e5eb9d
·
verified ·
1 Parent(s): e8ea55a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -75
app.py CHANGED
@@ -49,8 +49,6 @@ def respond(
49
  top_p,
50
  frequency_penalty,
51
  seed,
52
- provider,
53
- custom_api_key,
54
  custom_model,
55
  model_search_term,
56
  selected_model
@@ -61,23 +59,13 @@ def respond(
61
  print(f"System message: {system_message}")
62
  print(f"Max tokens: {max_tokens}, Temperature: {temperature}, Top-P: {top_p}")
63
  print(f"Frequency Penalty: {frequency_penalty}, Seed: {seed}")
64
- print(f"Selected provider: {provider}")
65
- print(f"Custom API Key provided: {bool(custom_api_key.strip())}")
66
  print(f"Selected model (custom_model): {custom_model}")
67
  print(f"Model search term: {model_search_term}")
68
  print(f"Selected model from radio: {selected_model}")
69
 
70
- # Determine which token to use
71
- token_to_use = custom_api_key if custom_api_key.strip() != "" else ACCESS_TOKEN
72
-
73
- if custom_api_key.strip() != "":
74
- print("USING CUSTOM API KEY: BYOK token provided by user is being used for authentication")
75
- else:
76
- print("USING DEFAULT API KEY: Environment variable HF_TOKEN is being used for authentication")
77
-
78
- # Initialize the Inference Client with the provider and appropriate token
79
- client = InferenceClient(token=token_to_use, provider=provider)
80
- print(f"Hugging Face Inference Client initialized with {provider} provider.")
81
 
82
  # Convert seed to None if -1 (meaning random)
83
  if seed == -1:
@@ -167,7 +155,7 @@ def respond(
167
 
168
  # Start with an empty string to build the response as tokens stream in
169
  response = ""
170
- print(f"Sending request to {provider} provider.")
171
 
172
  # Prepare parameters for the chat completion request
173
  parameters = {
@@ -211,19 +199,13 @@ def respond(
211
 
212
  print("Completed response generation.")
213
 
214
- # Function to validate provider selection based on BYOK
215
- def validate_provider(api_key, provider):
216
- if not api_key.strip() and provider != "hf-inference":
217
- return gr.update(value="hf-inference")
218
- return gr.update(value=provider)
219
-
220
  # GRADIO UI
221
  with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
222
  # Create the chatbot component
223
  chatbot = gr.Chatbot(
224
  height=600,
225
  show_copy_button=True,
226
- placeholder="Select a model and begin chatting. Now supports multiple inference providers and multimodal inputs",
227
  layout="panel"
228
  )
229
  print("Chatbot interface created.")
@@ -238,8 +220,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
238
  file_count="multiple",
239
  sources=["upload"]
240
  )
241
-
242
- # Note: We're removing the separate submit button since MultimodalTextbox has its own
243
 
244
  # Create accordion for settings
245
  with gr.Accordion("Settings", open=False):
@@ -294,34 +274,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
294
  label="Seed (-1 for random)"
295
  )
296
 
297
- # Provider selection
298
- providers_list = [
299
- "hf-inference", # Default Hugging Face Inference
300
- "cerebras", # Cerebras provider
301
- "together", # Together AI
302
- "sambanova", # SambaNova
303
- "novita", # Novita AI
304
- "cohere", # Cohere
305
- "fireworks-ai", # Fireworks AI
306
- "hyperbolic", # Hyperbolic
307
- "nebius", # Nebius
308
- ]
309
-
310
- provider_radio = gr.Radio(
311
- choices=providers_list,
312
- value="hf-inference",
313
- label="Inference Provider",
314
- )
315
-
316
- # New BYOK textbox
317
- byok_textbox = gr.Textbox(
318
- value="",
319
- label="BYOK (Bring Your Own Key)",
320
- info="Enter a custom Hugging Face API key here. When empty, only 'hf-inference' provider can be used.",
321
- placeholder="Enter your Hugging Face API token",
322
- type="password" # Hide the API key for security
323
- )
324
-
325
  # Custom model box
326
  custom_model_box = gr.Textbox(
327
  value="",
@@ -434,7 +386,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
434
  return history
435
 
436
  # Define bot response function
437
- def bot(history, system_msg, max_tokens, temperature, top_p, freq_penalty, seed, provider, api_key, custom_model, search_term, selected_model):
438
  # Check if history is valid
439
  if not history or len(history) == 0:
440
  print("No history to process")
@@ -481,8 +433,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
481
  top_p,
482
  freq_penalty,
483
  seed,
484
- provider,
485
- api_key,
486
  custom_model,
487
  search_term,
488
  selected_model
@@ -501,8 +451,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
501
  top_p,
502
  freq_penalty,
503
  seed,
504
- provider,
505
- api_key,
506
  custom_model,
507
  search_term,
508
  selected_model
@@ -519,7 +467,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
519
  ).then(
520
  bot,
521
  [chatbot, system_message_box, max_tokens_slider, temperature_slider, top_p_slider,
522
- frequency_penalty_slider, seed_slider, provider_radio, byok_textbox, custom_model_box,
523
  model_search_box, featured_model_radio],
524
  [chatbot]
525
  ).then(
@@ -543,22 +491,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
543
  outputs=custom_model_box
544
  )
545
  print("Featured model radio button change event linked.")
546
-
547
- # Connect the BYOK textbox to validate provider selection
548
- byok_textbox.change(
549
- fn=validate_provider,
550
- inputs=[byok_textbox, provider_radio],
551
- outputs=provider_radio
552
- )
553
- print("BYOK textbox change event linked.")
554
-
555
- # Also validate provider when the radio changes to ensure consistency
556
- provider_radio.change(
557
- fn=validate_provider,
558
- inputs=[byok_textbox, provider_radio],
559
- outputs=provider_radio
560
- )
561
- print("Provider radio button change event linked.")
562
 
563
  print("Gradio interface initialized.")
564
 
 
49
  top_p,
50
  frequency_penalty,
51
  seed,
 
 
52
  custom_model,
53
  model_search_term,
54
  selected_model
 
59
  print(f"System message: {system_message}")
60
  print(f"Max tokens: {max_tokens}, Temperature: {temperature}, Top-P: {top_p}")
61
  print(f"Frequency Penalty: {frequency_penalty}, Seed: {seed}")
 
 
62
  print(f"Selected model (custom_model): {custom_model}")
63
  print(f"Model search term: {model_search_term}")
64
  print(f"Selected model from radio: {selected_model}")
65
 
66
+ # Initialize the Inference Client with default HF inference
67
+ client = InferenceClient(token=ACCESS_TOKEN)
68
+ print(f"Hugging Face Inference Client initialized with standard HF inference.")
 
 
 
 
 
 
 
 
69
 
70
  # Convert seed to None if -1 (meaning random)
71
  if seed == -1:
 
155
 
156
  # Start with an empty string to build the response as tokens stream in
157
  response = ""
158
+ print(f"Sending request to Hugging Face inference.")
159
 
160
  # Prepare parameters for the chat completion request
161
  parameters = {
 
199
 
200
  print("Completed response generation.")
201
 
 
 
 
 
 
 
202
  # GRADIO UI
203
  with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
204
  # Create the chatbot component
205
  chatbot = gr.Chatbot(
206
  height=600,
207
  show_copy_button=True,
208
+ placeholder="Select a model and begin chatting. Now supports multimodal inputs.",
209
  layout="panel"
210
  )
211
  print("Chatbot interface created.")
 
220
  file_count="multiple",
221
  sources=["upload"]
222
  )
 
 
223
 
224
  # Create accordion for settings
225
  with gr.Accordion("Settings", open=False):
 
274
  label="Seed (-1 for random)"
275
  )
276
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  # Custom model box
278
  custom_model_box = gr.Textbox(
279
  value="",
 
386
  return history
387
 
388
  # Define bot response function
389
+ def bot(history, system_msg, max_tokens, temperature, top_p, freq_penalty, seed, custom_model, search_term, selected_model):
390
  # Check if history is valid
391
  if not history or len(history) == 0:
392
  print("No history to process")
 
433
  top_p,
434
  freq_penalty,
435
  seed,
 
 
436
  custom_model,
437
  search_term,
438
  selected_model
 
451
  top_p,
452
  freq_penalty,
453
  seed,
 
 
454
  custom_model,
455
  search_term,
456
  selected_model
 
467
  ).then(
468
  bot,
469
  [chatbot, system_message_box, max_tokens_slider, temperature_slider, top_p_slider,
470
+ frequency_penalty_slider, seed_slider, custom_model_box,
471
  model_search_box, featured_model_radio],
472
  [chatbot]
473
  ).then(
 
491
  outputs=custom_model_box
492
  )
493
  print("Featured model radio button change event linked.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494
 
495
  print("Gradio interface initialized.")
496