Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 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,6 +106,7 @@ def respond(
|
|
| 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,14 +149,6 @@ seed_slider = gr.Slider(
|
|
| 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
|
|
@@ -179,12 +171,6 @@ provider_radio = gr.Radio(
|
|
| 179 |
)
|
| 180 |
|
| 181 |
# Model selection components
|
| 182 |
-
model_search_box = gr.Textbox(
|
| 183 |
-
label="Filter Models",
|
| 184 |
-
placeholder="Search for a featured model...",
|
| 185 |
-
lines=1
|
| 186 |
-
)
|
| 187 |
-
|
| 188 |
models_list = [
|
| 189 |
"meta-llama/Llama-3.3-70B-Instruct",
|
| 190 |
"meta-llama/Llama-3.1-70B-Instruct",
|
|
@@ -237,43 +223,79 @@ def set_custom_model_from_radio(selected):
|
|
| 237 |
print(f"Featured model selected: {selected}")
|
| 238 |
return selected
|
| 239 |
|
| 240 |
-
# Create the Gradio interface
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
# Connect the model filter to update the radio choices
|
| 263 |
model_search_box.change(
|
| 264 |
fn=filter_models,
|
| 265 |
inputs=model_search_box,
|
| 266 |
-
outputs=
|
| 267 |
)
|
| 268 |
print("Model search box change event linked.")
|
| 269 |
|
| 270 |
# Connect the featured model radio to update the custom model box
|
| 271 |
-
|
| 272 |
fn=set_custom_model_from_radio,
|
| 273 |
-
inputs=
|
| 274 |
outputs=custom_model_box
|
| 275 |
)
|
| 276 |
print("Featured model radio button change event linked.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
print("Gradio interface initialized.")
|
| 279 |
|
|
|
|
| 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 |
|
| 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 |
label="Seed (-1 for random)"
|
| 150 |
)
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# Provider selection
|
| 153 |
providers_list = [
|
| 154 |
"hf-inference", # Default Hugging Face Inference
|
|
|
|
| 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 |
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 |
|