VeuReu commited on
Commit
18cf1c5
·
verified ·
1 Parent(s): c86d72a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -20
app.py CHANGED
@@ -229,35 +229,83 @@ h2 {
229
  }
230
  """
231
 
232
- with gr.Blocks(title="Salamandra 7B Instruct · ZeroGPU",css=custom_css,theme=gr.themes.Soft()) as demo:
233
- gr.Markdown("## Salamandra-7B-Instruct · ZeroGPU\nTexto respuesta instruccional.")
 
 
 
 
234
  with gr.Row():
235
  with gr.Column(scale=1):
236
- in_system = gr.Textbox(label="System (opcional)", value="")
237
- in_prompt = gr.Textbox(label="Prompt", placeholder="Escribe tu instrucción…", lines=6)
238
- max_new = gr.Slider(16, 2048, value=512, step=16, label="max_new_tokens")
239
- temp = gr.Slider(0.0, 1.5, value=0.7, step=0.05, label="temperature")
240
- top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.01, label="top_p")
 
 
 
 
 
 
 
 
 
 
 
241
  btn = gr.Button("Generar", variant="primary")
 
242
  with gr.Column(scale=1):
243
- out = gr.Textbox(label="Respuesta", lines=18)
 
 
 
 
 
 
 
 
 
 
244
 
245
- btn.click(generate_advanced, [in_prompt, in_system, max_new, temp, top_p], out, api_name="generate", concurrency_limit=1)
246
  gr.Markdown("---")
247
- # Endpoint minimalista compatible con el ENGINE (/predict: solo prompt)
248
- in_prompt_engine = gr.Textbox(label="Prompt (ENGINE)", value="Di hola en una frase.")
249
- out_engine = gr.Textbox(label="Respuesta (ENGINE)")
250
- gr.Button("Probar /predict").click(predict_for_engine, [in_prompt_engine], out_engine, api_name="predict", concurrency_limit=1)
 
 
 
 
 
 
 
 
 
 
 
 
251
  gr.Markdown("---")
252
-
 
 
253
  gr.Markdown('<h2 style="text-align:center">Resumir frases</h2>')
 
254
  with gr.Row():
255
  with gr.Column(scale=1):
 
256
  sentence = gr.Textbox(label="Frase a resumir", value="", lines=3)
 
 
257
  num_words = gr.Textbox(label="Nombre de paraules del resum", value="4")
 
258
  with gr.Column(scale=1):
 
259
  out_resume = gr.Textbox(label="Resposta", lines=18)
 
260
  with gr.Row():
 
261
  btn_resume = gr.Button("Resumir", variant="primary")
262
 
263
  btn_resume.click(
@@ -267,18 +315,28 @@ with gr.Blocks(title="Salamandra 7B Instruct · ZeroGPU",css=custom_css,theme=gr
267
  api_name="resume",
268
  concurrency_limit=1
269
  )
 
 
270
  gr.Markdown("---")
271
-
 
 
272
  gr.Markdown('<h2 style="text-align:center">Inclusió d’identitats</h2>')
 
273
  with gr.Row():
274
  with gr.Column(scale=1):
 
275
  sentence = gr.Textbox(label="Frase a modificar", value="", lines=3)
 
 
276
  person = gr.Textbox(label="Persones reconegudes", value='"Mireia Martí": 4, "Xavier Busquets": 5')
 
277
  with gr.Column(scale=1):
278
  out_modificat = gr.Textbox(label="Resposta", lines=18)
 
279
  with gr.Row():
280
  btn_modify = gr.Button("Modificar frase", variant="primary")
281
-
282
  btn_modify.click(
283
  identity_manager,
284
  inputs=[sentence, person],
@@ -287,11 +345,24 @@ with gr.Blocks(title="Salamandra 7B Instruct · ZeroGPU",css=custom_css,theme=gr
287
  concurrency_limit=1
288
  )
289
 
 
 
 
 
 
290
  gr.Markdown('<h2 style="text-align:center">Narració lliure</h2>')
 
291
  with gr.Row():
292
  with gr.Column(scale=1):
293
- srt = gr.Textbox(label="Audiodescripció", value="(AD)\nTOTS CANTANT: avui celebrem la nostra festa major\nAINA: som hi tots a ballar", lines=3)
 
 
 
 
 
 
294
  btn_modify = gr.Button("Generar narració lliure", variant="primary")
 
295
  with gr.Column(scale=1):
296
  narració_lliure = gr.Textbox(label="Narració lliure", lines=18)
297
 
@@ -303,15 +374,33 @@ with gr.Blocks(title="Salamandra 7B Instruct · ZeroGPU",css=custom_css,theme=gr
303
  concurrency_limit=1
304
  )
305
 
 
 
 
 
 
306
  gr.Markdown('<h2 style="text-align:center">Sortida del model Salamandra a partir d’una petició</h2>')
 
307
  with gr.Row():
308
- prompt = gr.Textbox(label="prompt", lines=10)
 
309
  with gr.Row():
310
  btn2 = gr.Button("Generar", variant="primary")
 
311
  with gr.Row():
312
- out2 = gr.JSON(label="Salida")
 
 
 
 
 
 
 
 
313
 
314
- btn2.click(salamandra_chat_endpoint, [prompt], out2, api_name="generate_out_from_prompt", concurrency_limit=1)
315
  gr.Markdown("---")
 
316
 
 
317
  demo.queue(max_size=16).launch()
 
229
  }
230
  """
231
 
232
+ # App UI built with Gradio. This interface exposes several model utilities.
233
+ with gr.Blocks(title="Salamandra 7B Instruct · ZeroGPU", css=custom_css, theme=gr.themes.Soft()) as demo:
234
+
235
+ # Section: Instruction-based text generation
236
+ gr.Markdown("## Salamandra-7B-Instruct · ZeroGPU\nText → resposta instruccional.")
237
+
238
  with gr.Row():
239
  with gr.Column(scale=1):
240
+ # System prompt (optional internal conditioning)
241
+ in_system = gr.Textbox(label="Sistema (opcional)", value="")
242
+
243
+ # User prompt to instruct the model
244
+ in_prompt = gr.Textbox(label="Instrucció", placeholder="Escriu la teva instrucció…", lines=6)
245
+
246
+ # Maximum number of new tokens to generate
247
+ max_new = gr.Slider(16, 2048, value=512, step=16, label="Màxim de tokens nous")
248
+
249
+ # Diversity parameter for randomness
250
+ temp = gr.Slider(0.0, 1.5, value=0.7, step=0.05, label="Temperatura")
251
+
252
+ # Nucleus sampling threshold
253
+ top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.01, label="Top-p")
254
+
255
+ # Button to trigger text generation
256
  btn = gr.Button("Generar", variant="primary")
257
+
258
  with gr.Column(scale=1):
259
+ # Output box for generated text
260
+ out = gr.Textbox(label="Resposta", lines=18)
261
+
262
+ # Bind main generation function
263
+ btn.click(
264
+ generate_advanced,
265
+ [in_prompt, in_system, max_new, temp, top_p],
266
+ out,
267
+ api_name="generate",
268
+ concurrency_limit=1
269
+ )
270
 
271
+ # --------------------------------------------------------------
272
  gr.Markdown("---")
273
+ # --------------------------------------------------------------
274
+
275
+ # Minimal endpoint for ENGINE compatibility (/predict)
276
+ # Only requires a prompt, returns generated text
277
+ in_prompt_engine = gr.Textbox(label="Instrucció (ENGINE)", value="Digues hola en una frase.")
278
+ out_engine = gr.Textbox(label="Resposta (ENGINE)")
279
+
280
+ gr.Button("Provar /predict").click(
281
+ predict_for_engine,
282
+ [in_prompt_engine],
283
+ out_engine,
284
+ api_name="predict",
285
+ concurrency_limit=1
286
+ )
287
+
288
+ # --------------------------------------------------------------
289
  gr.Markdown("---")
290
+ # --------------------------------------------------------------
291
+
292
+ # Section: Sentence summarization
293
  gr.Markdown('<h2 style="text-align:center">Resumir frases</h2>')
294
+
295
  with gr.Row():
296
  with gr.Column(scale=1):
297
+ # Text to summarize
298
  sentence = gr.Textbox(label="Frase a resumir", value="", lines=3)
299
+
300
+ # Desired number of words in the summary
301
  num_words = gr.Textbox(label="Nombre de paraules del resum", value="4")
302
+
303
  with gr.Column(scale=1):
304
+ # Output summary
305
  out_resume = gr.Textbox(label="Resposta", lines=18)
306
+
307
  with gr.Row():
308
+ # Button to produce a summary
309
  btn_resume = gr.Button("Resumir", variant="primary")
310
 
311
  btn_resume.click(
 
315
  api_name="resume",
316
  concurrency_limit=1
317
  )
318
+
319
+ # --------------------------------------------------------------
320
  gr.Markdown("---")
321
+ # --------------------------------------------------------------
322
+
323
+ # Section: Inclusion of identities inside text
324
  gr.Markdown('<h2 style="text-align:center">Inclusió d’identitats</h2>')
325
+
326
  with gr.Row():
327
  with gr.Column(scale=1):
328
+ # Sentence to modify
329
  sentence = gr.Textbox(label="Frase a modificar", value="", lines=3)
330
+
331
+ # Identity mapping provided by the user
332
  person = gr.Textbox(label="Persones reconegudes", value='"Mireia Martí": 4, "Xavier Busquets": 5')
333
+
334
  with gr.Column(scale=1):
335
  out_modificat = gr.Textbox(label="Resposta", lines=18)
336
+
337
  with gr.Row():
338
  btn_modify = gr.Button("Modificar frase", variant="primary")
339
+
340
  btn_modify.click(
341
  identity_manager,
342
  inputs=[sentence, person],
 
345
  concurrency_limit=1
346
  )
347
 
348
+ # --------------------------------------------------------------
349
+ gr.Markdown("---")
350
+ # --------------------------------------------------------------
351
+
352
+ # Section: Free narration generation from SRT-like audio description
353
  gr.Markdown('<h2 style="text-align:center">Narració lliure</h2>')
354
+
355
  with gr.Row():
356
  with gr.Column(scale=1):
357
+ # SRT-like structured description
358
+ srt = gr.Textbox(
359
+ label="Audiodescripció",
360
+ value="(AD)\nTOTS CANTANT: avui celebrem la nostra festa major\nAINA: som hi tots a ballar",
361
+ lines=3
362
+ )
363
+
364
  btn_modify = gr.Button("Generar narració lliure", variant="primary")
365
+
366
  with gr.Column(scale=1):
367
  narració_lliure = gr.Textbox(label="Narració lliure", lines=18)
368
 
 
374
  concurrency_limit=1
375
  )
376
 
377
+ # --------------------------------------------------------------
378
+ gr.Markdown("---")
379
+ # --------------------------------------------------------------
380
+
381
+ # Section: Raw model output from a prompt (JSON)
382
  gr.Markdown('<h2 style="text-align:center">Sortida del model Salamandra a partir d’una petició</h2>')
383
+
384
  with gr.Row():
385
+ prompt = gr.Textbox(label="Prompt", lines=10)
386
+
387
  with gr.Row():
388
  btn2 = gr.Button("Generar", variant="primary")
389
+
390
  with gr.Row():
391
+ out2 = gr.JSON(label="Sortida")
392
+
393
+ btn2.click(
394
+ salamandra_chat_endpoint,
395
+ [prompt],
396
+ out2,
397
+ api_name="generate_out_from_prompt",
398
+ concurrency_limit=1
399
+ )
400
 
401
+ # --------------------------------------------------------------
402
  gr.Markdown("---")
403
+ # --------------------------------------------------------------
404
 
405
+ # Queue to handle multiple requests safely
406
  demo.queue(max_size=16).launch()