Update app.py
Browse files
app.py
CHANGED
|
@@ -144,6 +144,28 @@ def salamandra_chat_endpoint(prompt: str) -> Dict[str, Any]:
|
|
| 144 |
|
| 145 |
return {"text": text}
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
# ------------------- HTTP (opcional, clientes puros) -------------------
|
| 148 |
# Si quieres, puedes a帽adir un endpoint HTTP POST /generate (FastAPI),
|
| 149 |
# pero con Gradio Client es suficiente para engine/local.
|
|
@@ -169,6 +191,7 @@ with gr.Blocks(title="Salamandra 7B Instruct 路 ZeroGPU") as demo:
|
|
| 169 |
out_engine = gr.Textbox(label="Respuesta (ENGINE)")
|
| 170 |
gr.Button("Probar /predict").click(predict_for_engine, [in_prompt_engine], out_engine, api_name="predict", concurrency_limit=1)
|
| 171 |
|
|
|
|
| 172 |
with gr.Row():
|
| 173 |
prompt = gr.Textbox(label="prompt", lines=10)
|
| 174 |
with gr.Row():
|
|
@@ -178,4 +201,38 @@ with gr.Blocks(title="Salamandra 7B Instruct 路 ZeroGPU") as demo:
|
|
| 178 |
|
| 179 |
btn2.click(salamandra_chat_endpoint, [prompt], out2, api_name="generate_out_from_prompt", concurrency_limit=1)
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
demo.queue(max_size=16).launch()
|
|
|
|
| 144 |
|
| 145 |
return {"text": text}
|
| 146 |
|
| 147 |
+
def resumir_frases(frase, num_palabras):
|
| 148 |
+
num_palabras = int(num_palabras)
|
| 149 |
+
prompt = f"Instruci贸: Resumeix la seg眉ent frase en {num_palabras} paraules. Input: {frase}"
|
| 150 |
+
result = generate_advanced(prompt=prompt, system="", max_new_tokens=512, temperature=0.7, top_p=0.95)
|
| 151 |
+
if "assistant" in result:
|
| 152 |
+
clean_output = result.split("assistant", 1)[1].strip().split("\n")[0]
|
| 153 |
+
else:
|
| 154 |
+
clean_output = frase
|
| 155 |
+
return clean_output
|
| 156 |
+
|
| 157 |
+
def identity_manager (frase, persona):
|
| 158 |
+
prompt = f"""Instrucci贸: Substitueix el subjecte de la frase per la persona indicada, mantenint la resta igual.
|
| 159 |
+
Frase: {frase}
|
| 160 |
+
Substituci贸: {persona}
|
| 161 |
+
Resposta:"""
|
| 162 |
+
result = generate_advanced(prompt=prompt, system="", max_new_tokens=512, temperature=0.7, top_p=0.95)
|
| 163 |
+
if "assistant" in result:
|
| 164 |
+
clean_output = result.split("assistant", 1)[1].strip().split("\n")[0]
|
| 165 |
+
else:
|
| 166 |
+
clean_output = frase
|
| 167 |
+
return clean_output
|
| 168 |
+
|
| 169 |
# ------------------- HTTP (opcional, clientes puros) -------------------
|
| 170 |
# Si quieres, puedes a帽adir un endpoint HTTP POST /generate (FastAPI),
|
| 171 |
# pero con Gradio Client es suficiente para engine/local.
|
|
|
|
| 191 |
out_engine = gr.Textbox(label="Respuesta (ENGINE)")
|
| 192 |
gr.Button("Probar /predict").click(predict_for_engine, [in_prompt_engine], out_engine, api_name="predict", concurrency_limit=1)
|
| 193 |
|
| 194 |
+
gr.Markdown('<h2 style="text-align:center">Sortida del model Salamandra a partir d'una petici贸</h2>')
|
| 195 |
with gr.Row():
|
| 196 |
prompt = gr.Textbox(label="prompt", lines=10)
|
| 197 |
with gr.Row():
|
|
|
|
| 201 |
|
| 202 |
btn2.click(salamandra_chat_endpoint, [prompt], out2, api_name="generate_out_from_prompt", concurrency_limit=1)
|
| 203 |
|
| 204 |
+
gr.Markdown('<h2 style="text-align:center">Resumir frases</h2>')
|
| 205 |
+
with gr.Row():
|
| 206 |
+
with gr.Column(scale=1):
|
| 207 |
+
frase = gr.Textbox(label="Frase a resumir", value="", lines=3)
|
| 208 |
+
num_paraules = gr.Textbox(label="Nombre de paraules del resum", value="4")
|
| 209 |
+
btn_resumir = gr.Button("Resumir", variant="primary")
|
| 210 |
+
with gr.Column(scale=1):
|
| 211 |
+
out_resumir = gr.Textbox(label="Resposta", lines=18)
|
| 212 |
+
|
| 213 |
+
btn_resumir.click(
|
| 214 |
+
resumir_frases,
|
| 215 |
+
inputs=[frase, num_paraules],
|
| 216 |
+
outputs=out_resumir,
|
| 217 |
+
api_name="resumir",
|
| 218 |
+
concurrency_limit=1
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
gr.Markdown('<h2 style="text-align:center">Inclusi贸 d鈥檌dentitats</h2>')
|
| 222 |
+
with gr.Row():
|
| 223 |
+
with gr.Column(scale=1):
|
| 224 |
+
frase = gr.Textbox(label="Frase a modificar", value="", lines=3)
|
| 225 |
+
persona = gr.Textbox(label="Persones reconegudes", value='"Mireia Mart铆": 4, "Xavier Busquets": 5')
|
| 226 |
+
btn_modificar = gr.Button("Modificar frase", variant="primary")
|
| 227 |
+
with gr.Column(scale=1):
|
| 228 |
+
out_modificat = gr.Textbox(label="Resposta", lines=18)
|
| 229 |
+
|
| 230 |
+
btn_modificar.click(
|
| 231 |
+
identity_manager,
|
| 232 |
+
inputs=[frase, persona],
|
| 233 |
+
outputs=out_modificat,
|
| 234 |
+
api_name="modificar",
|
| 235 |
+
concurrency_limit=1
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
demo.queue(max_size=16).launch()
|