Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,9 @@ def respond(
|
|
| 16 |
frequency_penalty,
|
| 17 |
seed,
|
| 18 |
custom_model,
|
| 19 |
-
provider #
|
|
|
|
|
|
|
| 20 |
):
|
| 21 |
print(f"Received message: {message}")
|
| 22 |
print(f"History: {history}")
|
|
@@ -25,6 +27,8 @@ def respond(
|
|
| 25 |
print(f"Frequency Penalty: {frequency_penalty}, Seed: {seed}")
|
| 26 |
print(f"Selected model (custom_model): {custom_model}")
|
| 27 |
print(f"Selected provider: {provider}")
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Initialize the Inference Client with the provider
|
| 30 |
# Provider is specified during initialization, not in the method call
|
|
@@ -54,8 +58,8 @@ def respond(
|
|
| 54 |
messages.append({"role": "user", "content": message})
|
| 55 |
print("Latest user message appended.")
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
model_to_use = custom_model.strip() if custom_model.strip() != "" else
|
| 59 |
print(f"Model selected for inference: {model_to_use}")
|
| 60 |
|
| 61 |
# Start with an empty string to build the response as tokens stream in
|
|
@@ -106,6 +110,7 @@ def respond(
|
|
| 106 |
chatbot = gr.Chatbot(height=600, show_copy_button=True, placeholder="Select a model and begin chatting", layout="panel")
|
| 107 |
print("Chatbot interface created.")
|
| 108 |
|
|
|
|
| 109 |
system_message_box = gr.Textbox(value="", placeholder="You are a helpful assistant.", label="System Prompt")
|
| 110 |
|
| 111 |
max_tokens_slider = gr.Slider(
|
|
@@ -113,7 +118,7 @@ max_tokens_slider = gr.Slider(
|
|
| 113 |
maximum=4096,
|
| 114 |
value=512,
|
| 115 |
step=1,
|
| 116 |
-
label="Max
|
| 117 |
)
|
| 118 |
temperature_slider = gr.Slider(
|
| 119 |
minimum=0.1,
|
|
@@ -144,7 +149,7 @@ seed_slider = gr.Slider(
|
|
| 144 |
label="Seed (-1 for random)"
|
| 145 |
)
|
| 146 |
|
| 147 |
-
#
|
| 148 |
custom_model_box = gr.Textbox(
|
| 149 |
value="",
|
| 150 |
label="Custom Model",
|
|
@@ -152,7 +157,7 @@ custom_model_box = gr.Textbox(
|
|
| 152 |
placeholder="meta-llama/Llama-3.3-70B-Instruct"
|
| 153 |
)
|
| 154 |
|
| 155 |
-
#
|
| 156 |
providers_list = [
|
| 157 |
"hf-inference", # Default Hugging Face Inference
|
| 158 |
"cerebras", # Cerebras provider
|
|
@@ -169,7 +174,6 @@ providers_list = [
|
|
| 169 |
"openai" # OpenAI compatible endpoints
|
| 170 |
]
|
| 171 |
|
| 172 |
-
# Provider selection dropdown for better UX with many options
|
| 173 |
provider_dropdown = gr.Dropdown(
|
| 174 |
choices=providers_list,
|
| 175 |
value="hf-inference",
|
|
@@ -177,6 +181,57 @@ provider_dropdown = gr.Dropdown(
|
|
| 177 |
info="Select which inference provider to use. Uses your Hugging Face PRO credits."
|
| 178 |
)
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
def set_custom_model_from_radio(selected):
|
| 181 |
"""
|
| 182 |
This function will get triggered whenever someone picks a model from the 'Featured Models' radio.
|
|
@@ -185,6 +240,7 @@ def set_custom_model_from_radio(selected):
|
|
| 185 |
print(f"Featured model selected: {selected}")
|
| 186 |
return selected
|
| 187 |
|
|
|
|
| 188 |
demo = gr.ChatInterface(
|
| 189 |
fn=respond,
|
| 190 |
additional_inputs=[
|
|
@@ -195,7 +251,9 @@ demo = gr.ChatInterface(
|
|
| 195 |
frequency_penalty_slider,
|
| 196 |
seed_slider,
|
| 197 |
custom_model_box,
|
| 198 |
-
provider_dropdown,
|
|
|
|
|
|
|
| 199 |
],
|
| 200 |
fill_height=True,
|
| 201 |
chatbot=chatbot,
|
|
@@ -204,102 +262,21 @@ demo = gr.ChatInterface(
|
|
| 204 |
print("ChatInterface object created.")
|
| 205 |
|
| 206 |
with demo:
|
| 207 |
-
#
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
### Provider Information
|
| 215 |
-
|
| 216 |
-
- **hf-inference**: Default Hugging Face Inference API
|
| 217 |
-
- **cerebras**: Cerebras AI models - extremely fast inference (70x faster than GPUs)
|
| 218 |
-
- **together**: Together AI models
|
| 219 |
-
- **sambanova**: SambaNova models
|
| 220 |
-
- **replicate**: Replicate models
|
| 221 |
-
- **fal-ai**: Fal.ai models
|
| 222 |
-
- **novita**: Novita AI
|
| 223 |
-
- **black-forest-labs**: Black Forest Labs
|
| 224 |
-
- **cohere**: Cohere models
|
| 225 |
-
- **fireworks-ai**: Fireworks AI
|
| 226 |
-
- **hyperbolic**: Hyperbolic models
|
| 227 |
-
- **nebius**: Nebius models
|
| 228 |
-
- **openai**: OpenAI compatible endpoints
|
| 229 |
-
|
| 230 |
-
As a PRO user, you receive $2 of credits monthly across all providers.
|
| 231 |
-
|
| 232 |
-
Note: Not all models are available on all providers. If you select a provider that doesn't support your chosen model, you'll get an error message.
|
| 233 |
-
""")
|
| 234 |
-
|
| 235 |
-
# Model selection components moved from the removed accordion
|
| 236 |
-
gr.Markdown("### Model Selection")
|
| 237 |
-
model_search_box = gr.Textbox(
|
| 238 |
-
label="Filter Models",
|
| 239 |
-
placeholder="Search for a featured model...",
|
| 240 |
-
lines=1
|
| 241 |
-
)
|
| 242 |
-
print("Model search box created.")
|
| 243 |
-
|
| 244 |
-
models_list = [
|
| 245 |
-
"meta-llama/Llama-3.3-70B-Instruct",
|
| 246 |
-
"meta-llama/Llama-3.1-70B-Instruct",
|
| 247 |
-
"meta-llama/Llama-3.0-70B-Instruct",
|
| 248 |
-
"meta-llama/Llama-3.2-3B-Instruct",
|
| 249 |
-
"meta-llama/Llama-3.2-1B-Instruct",
|
| 250 |
-
"meta-llama/Llama-3.1-8B-Instruct",
|
| 251 |
-
"NousResearch/Hermes-3-Llama-3.1-8B",
|
| 252 |
-
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 253 |
-
"mistralai/Mistral-Nemo-Instruct-2407",
|
| 254 |
-
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 255 |
-
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 256 |
-
"mistralai/Mistral-7B-Instruct-v0.2",
|
| 257 |
-
"Qwen/Qwen3-235B-A22B",
|
| 258 |
-
"Qwen/Qwen3-32B",
|
| 259 |
-
"Qwen/Qwen2.5-72B-Instruct",
|
| 260 |
-
"Qwen/Qwen2.5-3B-Instruct",
|
| 261 |
-
"Qwen/Qwen2.5-0.5B-Instruct",
|
| 262 |
-
"Qwen/QwQ-32B",
|
| 263 |
-
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 264 |
-
"microsoft/Phi-3.5-mini-instruct",
|
| 265 |
-
"microsoft/Phi-3-mini-128k-instruct",
|
| 266 |
-
"microsoft/Phi-3-mini-4k-instruct",
|
| 267 |
-
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 268 |
-
"deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
| 269 |
-
"HuggingFaceH4/zephyr-7b-beta",
|
| 270 |
-
"HuggingFaceTB/SmolLM2-360M-Instruct",
|
| 271 |
-
"tiiuae/falcon-7b-instruct",
|
| 272 |
-
"01-ai/Yi-1.5-34B-Chat",
|
| 273 |
-
]
|
| 274 |
-
print("Models list initialized.")
|
| 275 |
-
|
| 276 |
-
featured_model_radio = gr.Radio(
|
| 277 |
-
label="Select a model below",
|
| 278 |
-
choices=models_list,
|
| 279 |
-
value="meta-llama/Llama-3.3-70B-Instruct",
|
| 280 |
-
interactive=True
|
| 281 |
-
)
|
| 282 |
-
print("Featured models radio button created.")
|
| 283 |
-
|
| 284 |
-
def filter_models(search_term):
|
| 285 |
-
print(f"Filtering models with search term: {search_term}")
|
| 286 |
-
filtered = [m for m in models_list if search_term.lower() in m.lower()]
|
| 287 |
-
print(f"Filtered models: {filtered}")
|
| 288 |
-
return gr.update(choices=filtered)
|
| 289 |
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
featured_model_radio.change(
|
| 298 |
-
fn=set_custom_model_from_radio,
|
| 299 |
-
inputs=featured_model_radio,
|
| 300 |
-
outputs=custom_model_box
|
| 301 |
-
)
|
| 302 |
-
print("Featured model radio button change event linked.")
|
| 303 |
|
| 304 |
print("Gradio interface initialized.")
|
| 305 |
|
|
|
|
| 16 |
frequency_penalty,
|
| 17 |
seed,
|
| 18 |
custom_model,
|
| 19 |
+
provider, # Provider selection
|
| 20 |
+
model_search_term, # For filtering models
|
| 21 |
+
selected_model # From radio button selection
|
| 22 |
):
|
| 23 |
print(f"Received message: {message}")
|
| 24 |
print(f"History: {history}")
|
|
|
|
| 27 |
print(f"Frequency Penalty: {frequency_penalty}, Seed: {seed}")
|
| 28 |
print(f"Selected model (custom_model): {custom_model}")
|
| 29 |
print(f"Selected provider: {provider}")
|
| 30 |
+
print(f"Model search term: {model_search_term}")
|
| 31 |
+
print(f"Selected model from radio: {selected_model}")
|
| 32 |
|
| 33 |
# Initialize the Inference Client with the provider
|
| 34 |
# Provider is specified during initialization, not in the method call
|
|
|
|
| 58 |
messages.append({"role": "user", "content": message})
|
| 59 |
print("Latest user message appended.")
|
| 60 |
|
| 61 |
+
# Determine which model to use, prioritizing custom_model if provided
|
| 62 |
+
model_to_use = custom_model.strip() if custom_model.strip() != "" else selected_model
|
| 63 |
print(f"Model selected for inference: {model_to_use}")
|
| 64 |
|
| 65 |
# Start with an empty string to build the response as tokens stream in
|
|
|
|
| 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 |
|
| 113 |
+
# Basic input components
|
| 114 |
system_message_box = gr.Textbox(value="", placeholder="You are a helpful assistant.", label="System Prompt")
|
| 115 |
|
| 116 |
max_tokens_slider = gr.Slider(
|
|
|
|
| 118 |
maximum=4096,
|
| 119 |
value=512,
|
| 120 |
step=1,
|
| 121 |
+
label="Max tokens"
|
| 122 |
)
|
| 123 |
temperature_slider = gr.Slider(
|
| 124 |
minimum=0.1,
|
|
|
|
| 149 |
label="Seed (-1 for random)"
|
| 150 |
)
|
| 151 |
|
| 152 |
+
# Custom model box
|
| 153 |
custom_model_box = gr.Textbox(
|
| 154 |
value="",
|
| 155 |
label="Custom 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
|
|
|
|
| 174 |
"openai" # OpenAI compatible endpoints
|
| 175 |
]
|
| 176 |
|
|
|
|
| 177 |
provider_dropdown = gr.Dropdown(
|
| 178 |
choices=providers_list,
|
| 179 |
value="hf-inference",
|
|
|
|
| 181 |
info="Select which inference provider to use. Uses your Hugging Face PRO credits."
|
| 182 |
)
|
| 183 |
|
| 184 |
+
# Model selection components
|
| 185 |
+
model_search_box = gr.Textbox(
|
| 186 |
+
label="Filter Models",
|
| 187 |
+
placeholder="Search for a featured model...",
|
| 188 |
+
lines=1
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
models_list = [
|
| 192 |
+
"meta-llama/Llama-3.3-70B-Instruct",
|
| 193 |
+
"meta-llama/Llama-3.1-70B-Instruct",
|
| 194 |
+
"meta-llama/Llama-3.0-70B-Instruct",
|
| 195 |
+
"meta-llama/Llama-3.2-3B-Instruct",
|
| 196 |
+
"meta-llama/Llama-3.2-1B-Instruct",
|
| 197 |
+
"meta-llama/Llama-3.1-8B-Instruct",
|
| 198 |
+
"NousResearch/Hermes-3-Llama-3.1-8B",
|
| 199 |
+
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 200 |
+
"mistralai/Mistral-Nemo-Instruct-2407",
|
| 201 |
+
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 202 |
+
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 203 |
+
"mistralai/Mistral-7B-Instruct-v0.2",
|
| 204 |
+
"Qwen/Qwen3-235B-A22B",
|
| 205 |
+
"Qwen/Qwen3-32B",
|
| 206 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
| 207 |
+
"Qwen/Qwen2.5-3B-Instruct",
|
| 208 |
+
"Qwen/Qwen2.5-0.5B-Instruct",
|
| 209 |
+
"Qwen/QwQ-32B",
|
| 210 |
+
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 211 |
+
"microsoft/Phi-3.5-mini-instruct",
|
| 212 |
+
"microsoft/Phi-3-mini-128k-instruct",
|
| 213 |
+
"microsoft/Phi-3-mini-4k-instruct",
|
| 214 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 215 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
| 216 |
+
"HuggingFaceH4/zephyr-7b-beta",
|
| 217 |
+
"HuggingFaceTB/SmolLM2-360M-Instruct",
|
| 218 |
+
"tiiuae/falcon-7b-instruct",
|
| 219 |
+
"01-ai/Yi-1.5-34B-Chat",
|
| 220 |
+
]
|
| 221 |
+
|
| 222 |
+
featured_model_radio = gr.Radio(
|
| 223 |
+
label="Select a model below",
|
| 224 |
+
choices=models_list,
|
| 225 |
+
value="meta-llama/Llama-3.3-70B-Instruct",
|
| 226 |
+
interactive=True
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
def filter_models(search_term):
|
| 230 |
+
print(f"Filtering models with search term: {search_term}")
|
| 231 |
+
filtered = [m for m in models_list if search_term.lower() in m.lower()]
|
| 232 |
+
print(f"Filtered models: {filtered}")
|
| 233 |
+
return gr.update(choices=filtered)
|
| 234 |
+
|
| 235 |
def set_custom_model_from_radio(selected):
|
| 236 |
"""
|
| 237 |
This function will get triggered whenever someone picks a model from the 'Featured Models' radio.
|
|
|
|
| 240 |
print(f"Featured model selected: {selected}")
|
| 241 |
return selected
|
| 242 |
|
| 243 |
+
# Create the Gradio interface
|
| 244 |
demo = gr.ChatInterface(
|
| 245 |
fn=respond,
|
| 246 |
additional_inputs=[
|
|
|
|
| 251 |
frequency_penalty_slider,
|
| 252 |
seed_slider,
|
| 253 |
custom_model_box,
|
| 254 |
+
provider_dropdown, # Provider selection
|
| 255 |
+
model_search_box, # Model search box
|
| 256 |
+
featured_model_radio # Featured model radio
|
| 257 |
],
|
| 258 |
fill_height=True,
|
| 259 |
chatbot=chatbot,
|
|
|
|
| 262 |
print("ChatInterface object created.")
|
| 263 |
|
| 264 |
with demo:
|
| 265 |
+
# Connect the model filter to update the radio choices
|
| 266 |
+
model_search_box.change(
|
| 267 |
+
fn=filter_models,
|
| 268 |
+
inputs=model_search_box,
|
| 269 |
+
outputs=featured_model_radio
|
| 270 |
+
)
|
| 271 |
+
print("Model search box change event linked.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
+
# Connect the featured model radio to update the custom model box
|
| 274 |
+
featured_model_radio.change(
|
| 275 |
+
fn=set_custom_model_from_radio,
|
| 276 |
+
inputs=featured_model_radio,
|
| 277 |
+
outputs=custom_model_box
|
| 278 |
+
)
|
| 279 |
+
print("Featured model radio button change event linked.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
print("Gradio interface initialized.")
|
| 282 |
|