Update app.py
Browse files
app.py
CHANGED
|
@@ -224,32 +224,93 @@ def salamandra_chat_endpoint(prompt: str) -> Dict[str, Any]:
|
|
| 224 |
|
| 225 |
# =================== UI ===================
|
| 226 |
|
|
|
|
| 227 |
with gr.Blocks(title="Salamandra 7B Tools · ZeroGPU") as demo:
|
| 228 |
-
|
|
|
|
|
|
|
| 229 |
|
| 230 |
with gr.Row():
|
| 231 |
with gr.Column():
|
| 232 |
-
messages = gr.Textbox(label="messages_json", value='[{"role":"user","content":"¿Cuánto es (2+2)^3?"}]', lines=6)
|
| 233 |
-
tools = gr.Textbox(label="tools_json (opcional)", value='[{"type":"function","function":{"name":"calculator","description":"Evalúa expresiones aritméticas básicas.","parameters":{"type":"object","properties":{"expr":{"type":"string"}},"required":["expr"]}}}]', lines=6)
|
| 234 |
-
max_new = gr.Slider(16, 2048, value=512, step=16, label="max_new_tokens")
|
| 235 |
-
temp = gr.Slider(0.0, 1.5, value=0.7, step=0.05, label="temperature")
|
| 236 |
-
topp = gr.Slider(0.1, 1.0, value=0.95, step=0.01, label="top_p")
|
| 237 |
-
btn = gr.Button("Generar", variant="primary")
|
| 238 |
-
with gr.Column():
|
| 239 |
-
out = gr.JSON(label="Salida")
|
| 240 |
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
-
|
| 244 |
-
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
with gr.Row():
|
| 247 |
-
prompt = gr.Textbox(label="
|
|
|
|
| 248 |
with gr.Row():
|
| 249 |
btn2 = gr.Button("Generar", variant="primary")
|
|
|
|
| 250 |
with gr.Row():
|
| 251 |
-
out2 = gr.JSON(label="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
-
|
|
|
|
|
|
|
| 254 |
|
|
|
|
| 255 |
demo.queue(max_size=16).launch()
|
|
|
|
| 224 |
|
| 225 |
# =================== UI ===================
|
| 226 |
|
| 227 |
+
# Main interface for Salamandra 7B Tools: supports tool specification (function calling)
|
| 228 |
with gr.Blocks(title="Salamandra 7B Tools · ZeroGPU") as demo:
|
| 229 |
+
|
| 230 |
+
# Header description for the UI
|
| 231 |
+
gr.Markdown("## Salamandra-7B-Tools · ZeroGPU\nXat amb especificació d'eines (function-calling).")
|
| 232 |
|
| 233 |
with gr.Row():
|
| 234 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
+
# JSON array of messages passed to the model
|
| 237 |
+
messages = gr.Textbox(
|
| 238 |
+
label="Missatges (JSON)",
|
| 239 |
+
value='[{"role":"user","content":"Quant és (2+2)^3?"}]',
|
| 240 |
+
lines=6
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
# Tool definitions in JSON schema format
|
| 244 |
+
tools = gr.Textbox(
|
| 245 |
+
label="Eines (JSON, opcional)",
|
| 246 |
+
value='[{"type":"function","function":{"name":"calculator","description":"Avalua expressions aritmètiques bàsiques.","parameters":{"type":"object","properties":{"expr":{"type":"string"}},"required":["expr"]}}}]',
|
| 247 |
+
lines=6
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
# Maximum generation length
|
| 251 |
+
max_new = gr.Slider(16, 2048, value=512, step=16, label="Màxim de tokens nous")
|
| 252 |
+
|
| 253 |
+
# Temperature for randomness
|
| 254 |
+
temp = gr.Slider(0.0, 1.5, value=0.7, step=0.05, label="Temperatura")
|
| 255 |
|
| 256 |
+
# Nucleus sampling threshold
|
| 257 |
+
topp = gr.Slider(0.1, 1.0, value=0.95, step=0.01, label="Top-p")
|
| 258 |
|
| 259 |
+
# Button to generate a response
|
| 260 |
+
btn = gr.Button("Generar", variant="primary")
|
| 261 |
+
|
| 262 |
+
with gr.Column():
|
| 263 |
+
# JSON output from the model
|
| 264 |
+
out = gr.JSON(label="Sortida")
|
| 265 |
+
|
| 266 |
+
# Bind chat-with-tools generation
|
| 267 |
+
btn.click(
|
| 268 |
+
chat_advanced,
|
| 269 |
+
[messages, tools, max_new, temp, topp],
|
| 270 |
+
out,
|
| 271 |
+
api_name="chat",
|
| 272 |
+
concurrency_limit=1
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
# --------------------------------------------------------------
|
| 276 |
+
gr.Markdown("---")
|
| 277 |
+
# --------------------------------------------------------------
|
| 278 |
+
|
| 279 |
+
# Minimal /predict endpoint for ENGINE compatibility
|
| 280 |
+
# Accepts messages + tool definitions
|
| 281 |
+
gr.Button("Provar /predict").click(
|
| 282 |
+
predict_for_engine,
|
| 283 |
+
[messages, tools],
|
| 284 |
+
out,
|
| 285 |
+
api_name="predict",
|
| 286 |
+
concurrency_limit=1
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
# --------------------------------------------------------------
|
| 290 |
+
gr.Markdown("---")
|
| 291 |
+
# --------------------------------------------------------------
|
| 292 |
+
|
| 293 |
+
# Endpoint: raw prompt → model output (JSON)
|
| 294 |
with gr.Row():
|
| 295 |
+
prompt = gr.Textbox(label="Prompt", lines=10)
|
| 296 |
+
|
| 297 |
with gr.Row():
|
| 298 |
btn2 = gr.Button("Generar", variant="primary")
|
| 299 |
+
|
| 300 |
with gr.Row():
|
| 301 |
+
out2 = gr.JSON(label="Sortida")
|
| 302 |
+
|
| 303 |
+
btn2.click(
|
| 304 |
+
salamandra_chat_endpoint,
|
| 305 |
+
[prompt],
|
| 306 |
+
out2,
|
| 307 |
+
api_name="generate_out_from_prompt",
|
| 308 |
+
concurrency_limit=1
|
| 309 |
+
)
|
| 310 |
|
| 311 |
+
# --------------------------------------------------------------
|
| 312 |
+
gr.Markdown("---")
|
| 313 |
+
# --------------------------------------------------------------
|
| 314 |
|
| 315 |
+
# Enable request queue for concurrency safety
|
| 316 |
demo.queue(max_size=16).launch()
|