Nymbo commited on
Commit
ea82e64
·
verified ·
1 Parent(s): 2f60481

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -63
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
 
4
 
5
  ACCESS_TOKEN = os.getenv("HF_TOKEN")
6
  print("Access token loaded.")
@@ -106,7 +107,6 @@ def respond(
106
 
107
  # GRADIO UI
108
 
109
- # Define all the UI components first
110
  chatbot = gr.Chatbot(height=600, show_copy_button=True, placeholder="Select a model and begin chatting", layout="panel")
111
  print("Chatbot interface created.")
112
 
@@ -149,6 +149,14 @@ seed_slider = gr.Slider(
149
  label="Seed (-1 for random)"
150
  )
151
 
 
 
 
 
 
 
 
 
152
  # Provider selection
153
  providers_list = [
154
  "hf-inference", # Default Hugging Face Inference
@@ -160,7 +168,6 @@ providers_list = [
160
  "fireworks-ai", # Fireworks AI
161
  "hyperbolic", # Hyperbolic
162
  "nebius", # Nebius
163
- "openai" # OpenAI compatible endpoints
164
  ]
165
 
166
  provider_radio = gr.Radio(
@@ -171,6 +178,12 @@ provider_radio = gr.Radio(
171
  )
172
 
173
  # Model selection components
 
 
 
 
 
 
174
  models_list = [
175
  "meta-llama/Llama-3.3-70B-Instruct",
176
  "meta-llama/Llama-3.1-70B-Instruct",
@@ -223,79 +236,43 @@ def set_custom_model_from_radio(selected):
223
  print(f"Featured model selected: {selected}")
224
  return selected
225
 
226
- # Create the Gradio interface with blocks for more control
227
- with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
228
- with gr.Row():
229
- # Create the main chat area
230
- with gr.Column(scale=3):
231
- # Add the chatbot UI
232
- chat_interface = gr.ChatInterface(
233
- respond,
234
- chatbot=chatbot,
235
- additional_inputs=[
236
- system_message_box,
237
- max_tokens_slider,
238
- temperature_slider,
239
- top_p_slider,
240
- frequency_penalty_slider,
241
- seed_slider,
242
- # These will be added manually outside the ChatInterface
243
- # custom_model_box,
244
- # model_search_box,
245
- provider_radio,
246
- # featured_model_radio will be linked manually
247
- ]
248
- )
249
-
250
- # Put the "Custom Model" and "Filter Models" textboxes in the same row
251
- with gr.Row():
252
- with gr.Column(scale=1):
253
- custom_model_box = gr.Textbox(
254
- value="",
255
- label="Custom Model",
256
- info="(Optional) Provide a custom Hugging Face model path. Overrides any selected featured model.",
257
- placeholder="meta-llama/Llama-3.3-70B-Instruct"
258
- )
259
- with gr.Column(scale=1):
260
- model_search_box = gr.Textbox(
261
- label="Filter Models",
262
- placeholder="Search for a featured model...",
263
- lines=1
264
- )
265
-
266
- # Add the featured model radio separately
267
- featured_model_radio_display = gr.Radio(
268
- label="Select a model below",
269
- choices=models_list,
270
- value="meta-llama/Llama-3.3-70B-Instruct",
271
- interactive=True
272
- )
273
-
274
  # Connect the model filter to update the radio choices
275
  model_search_box.change(
276
  fn=filter_models,
277
  inputs=model_search_box,
278
- outputs=featured_model_radio_display
279
  )
280
  print("Model search box change event linked.")
281
 
282
  # Connect the featured model radio to update the custom model box
283
- featured_model_radio_display.change(
284
  fn=set_custom_model_from_radio,
285
- inputs=featured_model_radio_display,
286
  outputs=custom_model_box
287
  )
288
  print("Featured model radio button change event linked.")
289
-
290
- # Make sure the custom model and selected model are passed to the respond function
291
- def modified_respond(*args):
292
- # The last two arguments are supposed to be model_search_term and selected_model
293
- args_list = list(args)
294
- args_list[-2] = model_search_box.value # Set the model_search_term
295
- args_list[-1] = featured_model_radio_display.value # Set the selected_model
296
- return respond(*args_list)
297
-
298
- chat_interface.chatbot.submit_callback = modified_respond
299
 
300
  print("Gradio interface initialized.")
301
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
+ import json
5
 
6
  ACCESS_TOKEN = os.getenv("HF_TOKEN")
7
  print("Access token loaded.")
 
107
 
108
  # GRADIO UI
109
 
 
110
  chatbot = gr.Chatbot(height=600, show_copy_button=True, placeholder="Select a model and begin chatting", layout="panel")
111
  print("Chatbot interface created.")
112
 
 
149
  label="Seed (-1 for random)"
150
  )
151
 
152
+ # Custom model box
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
 
168
  "fireworks-ai", # Fireworks AI
169
  "hyperbolic", # Hyperbolic
170
  "nebius", # Nebius
 
171
  ]
172
 
173
  provider_radio = gr.Radio(
 
178
  )
179
 
180
  # Model selection components
181
+ model_search_box = gr.Textbox(
182
+ label="Filter Models",
183
+ placeholder="Search for a featured model...",
184
+ lines=1
185
+ )
186
+
187
  models_list = [
188
  "meta-llama/Llama-3.3-70B-Instruct",
189
  "meta-llama/Llama-3.1-70B-Instruct",
 
236
  print(f"Featured model selected: {selected}")
237
  return selected
238
 
239
+ # Create the Gradio interface
240
+ demo = gr.ChatInterface(
241
+ fn=respond,
242
+ additional_inputs=[
243
+ system_message_box,
244
+ max_tokens_slider,
245
+ temperature_slider,
246
+ top_p_slider,
247
+ frequency_penalty_slider,
248
+ seed_slider,
249
+ custom_model_box,
250
+ provider_radio, # Provider selection
251
+ model_search_box, # Model search box
252
+ featured_model_radio # Featured model radio
253
+ ],
254
+ fill_height=True,
255
+ chatbot=chatbot,
256
+ theme="Nymbo/Nymbo_Theme",
257
+ )
258
+ print("ChatInterface object created.")
259
+
260
+ with demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  # Connect the model filter to update the radio choices
262
  model_search_box.change(
263
  fn=filter_models,
264
  inputs=model_search_box,
265
+ outputs=featured_model_radio
266
  )
267
  print("Model search box change event linked.")
268
 
269
  # Connect the featured model radio to update the custom model box
270
+ featured_model_radio.change(
271
  fn=set_custom_model_from_radio,
272
+ inputs=featured_model_radio,
273
  outputs=custom_model_box
274
  )
275
  print("Featured model radio button change event linked.")
 
 
 
 
 
 
 
 
 
 
276
 
277
  print("Gradio interface initialized.")
278