Summarization / appImage.py
ikraamkb's picture
Update appImage.py
e88e7c9 verified
raw
history blame
732 Bytes
@app.post("/imagecaption/")
async def caption_from_frontend(file: UploadFile):
try:
# Save temp image
contents = await file.read()
tmp_path = os.path.join(tempfile.gettempdir(), file.filename)
with open(tmp_path, "wb") as f:
f.write(contents)
caption = generate_caption(tmp_path)
# Generate audio
audio_path = os.path.join(tempfile.gettempdir(), file.filename + ".mp3")
tts = gTTS(text=caption)
tts.save(audio_path)
return JSONResponse({
"answer": caption,
"audio": f"/files/{os.path.basename(audio_path)}"
})
except Exception as e:
return JSONResponse({"error": str(e)}, status_code=500)