Spaces:
Running
Running
Update app.py
Browse files
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
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
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=
|
279 |
)
|
280 |
print("Model search box change event linked.")
|
281 |
|
282 |
# Connect the featured model radio to update the custom model box
|
283 |
-
|
284 |
fn=set_custom_model_from_radio,
|
285 |
-
inputs=
|
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 |
|