dippoo commited on
Commit
302a193
·
1 Parent(s): 79598c0

Add /pod/jobs/{id}/image endpoint, show generated image directly in UI

Browse files
src/content_engine/api/routes_pod.py CHANGED
@@ -772,6 +772,23 @@ async def get_pod_job(job_id: str):
772
  return job
773
 
774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775
  def _build_flux_workflow(
776
  prompt: str,
777
  negative_prompt: str,
 
772
  return job
773
 
774
 
775
+ @router.get("/jobs/{job_id}/image")
776
+ async def get_pod_job_image(job_id: str):
777
+ """Serve the generated image for a completed pod job."""
778
+ from fastapi.responses import FileResponse
779
+ job = _pod_jobs.get(job_id)
780
+ if not job:
781
+ raise HTTPException(404, "Job not found")
782
+ output_path = job.get("output_path")
783
+ if not output_path:
784
+ raise HTTPException(404, "No image yet")
785
+ from pathlib import Path
786
+ p = Path(output_path)
787
+ if not p.exists():
788
+ raise HTTPException(404, "Image file not found")
789
+ return FileResponse(p, media_type="image/png")
790
+
791
+
792
  def _build_flux_workflow(
793
  prompt: str,
794
  negative_prompt: str,
src/content_engine/api/ui.html CHANGED
@@ -2455,14 +2455,12 @@ async function pollPodJob(jobId, startTime) {
2455
 
2456
  if (job.status === 'completed' && job.output_path) {
2457
  document.getElementById('gen-time').textContent = `${elapsed}s`;
2458
- // Fetch latest image from gallery
2459
- const imgRes = await fetch(API + '/api/images?limit=1');
2460
- const images = await imgRes.json();
2461
- if (images.length > 0) {
2462
- showPreviewImage(images[0]);
2463
- } else {
2464
- preview.innerHTML = `<div class="preview-placeholder"><p>Image saved to: ${job.output_path}</p></div>`;
2465
- }
2466
  toast('Image generated!', 'success');
2467
  return;
2468
  }
 
2455
 
2456
  if (job.status === 'completed' && job.output_path) {
2457
  document.getElementById('gen-time').textContent = `${elapsed}s`;
2458
+ // Show image directly from pod job endpoint
2459
+ preview.innerHTML = `
2460
+ <div style="text-align:center;width:100%">
2461
+ <img src="${API}/api/pod/jobs/${jobId}/image" alt="Generated image" style="max-width:100%;max-height:70vh;border-radius:8px;margin-bottom:12px">
2462
+ <p style="color:var(--text-secondary);font-size:12px">${elapsed}s on RunPod GPU</p>
2463
+ </div>`;
 
 
2464
  toast('Image generated!', 'success');
2465
  return;
2466
  }