Cristobal commited on
Commit
4ccfdce
·
1 Parent(s): 8a19230

selector parte del PDF auto/principio/mitad/final

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -148,6 +148,21 @@ async def ep_guion(request: Request):
148
  d = await request.json()
149
  texto = d.get("texto","").strip()
150
  estilo = d.get("estilo","narrativo")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  if not texto:
152
  return JSONResponse({"error":"Pega tu contenido base primero"}, status_code=400)
153
  try:
@@ -241,9 +256,9 @@ async def ep_pdf(file: UploadFile = File(...)):
241
  texto = texto.strip()
242
  if not texto:
243
  return JSONResponse({"error":"El PDF no tiene texto extraible (puede ser escaneado)"}, status_code=400)
244
- texto = texto[:6000]
245
- ESTADO["texto_base"] = texto
246
- return {"ok": True, "texto": texto, "caracteres": len(texto)}
247
  except Exception as e:
248
  return JSONResponse({"error": str(e)[:120]}, status_code=500)
249
 
@@ -288,6 +303,13 @@ audio,video{width:100%;margin-top:10px;border-radius:8px}
288
  <option value="publicitario">Publicitario y persuasivo</option>
289
  <option value="misterio">Misterio e intriga</option>
290
  </select>
 
 
 
 
 
 
 
291
  <button onclick="genGuion()">Generar Propuesta de Guion</button>
292
  <div class="msg" id="msgGuion"></div>
293
  </div>
@@ -356,7 +378,7 @@ async function subirPdf(){
356
  }
357
  async function genGuion(){
358
  var m=document.getElementById("msgGuion");m.textContent="Generando...";m.style.color="#ffb700";
359
- var r=await fetch("/generar-guion",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({texto:document.getElementById("texto").value,estilo:document.getElementById("estilo").value})});
360
  var d=await r.json();
361
  if(d.guion){document.getElementById("guion").value=d.guion;m.textContent="Guion listo. Editalo abajo si quieres.";m.style.color="#00c853";}
362
  else{m.textContent=d.error;m.style.color="#ff5252";}
 
148
  d = await request.json()
149
  texto = d.get("texto","").strip()
150
  estilo = d.get("estilo","narrativo")
151
+ parte = d.get("parte","auto")
152
+ # Si hay PDF completo cargado y el usuario no edito el texto a mano, usar el trozo elegido
153
+ completo = ESTADO.get("texto_completo","")
154
+ if completo and len(completo) > 6000:
155
+ if parte == "principio":
156
+ texto = completo[:6000]
157
+ elif parte == "mitad":
158
+ m = len(completo)//2
159
+ texto = completo[m-3000:m+3000]
160
+ elif parte == "final":
161
+ texto = completo[-6000:]
162
+ else: # auto = trozo al azar
163
+ import random as _r
164
+ ini = _r.randint(0, max(0, len(completo)-6000))
165
+ texto = completo[ini:ini+6000]
166
  if not texto:
167
  return JSONResponse({"error":"Pega tu contenido base primero"}, status_code=400)
168
  try:
 
256
  texto = texto.strip()
257
  if not texto:
258
  return JSONResponse({"error":"El PDF no tiene texto extraible (puede ser escaneado)"}, status_code=400)
259
+ ESTADO["texto_completo"] = texto
260
+ # Mostrar preview de los primeros 6000 al usuario
261
+ return {"ok": True, "texto": texto[:6000], "caracteres": len(texto)}
262
  except Exception as e:
263
  return JSONResponse({"error": str(e)[:120]}, status_code=500)
264
 
 
303
  <option value="publicitario">Publicitario y persuasivo</option>
304
  <option value="misterio">Misterio e intriga</option>
305
  </select>
306
+ <span class="lbl">Que parte del documento usar (si subiste PDF largo):</span>
307
+ <select id="parte">
308
+ <option value="auto">Automatico (trozos al azar, mas variedad)</option>
309
+ <option value="principio">Principio del documento</option>
310
+ <option value="mitad">Mitad del documento</option>
311
+ <option value="final">Final del documento</option>
312
+ </select>
313
  <button onclick="genGuion()">Generar Propuesta de Guion</button>
314
  <div class="msg" id="msgGuion"></div>
315
  </div>
 
378
  }
379
  async function genGuion(){
380
  var m=document.getElementById("msgGuion");m.textContent="Generando...";m.style.color="#ffb700";
381
+ var r=await fetch("/generar-guion",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({texto:document.getElementById("texto").value,estilo:document.getElementById("estilo").value,parte:document.getElementById("parte").value})});
382
  var d=await r.json();
383
  if(d.guion){document.getElementById("guion").value=d.guion;m.textContent="Guion listo. Editalo abajo si quieres.";m.style.color="#00c853";}
384
  else{m.textContent=d.error;m.style.color="#ff5252";}