ikraamkb commited on
Commit
889642a
·
verified ·
1 Parent(s): 6be72e5

Update appImage.py

Browse files
Files changed (1) hide show
  1. appImage.py +12 -19
appImage.py CHANGED
@@ -1,23 +1,16 @@
1
  @app.post("/imagecaption/")
2
- async def caption_from_frontend(file: UploadFile):
3
  try:
4
- # Save temp image
5
- contents = await file.read()
6
- tmp_path = os.path.join(tempfile.gettempdir(), file.filename)
7
- with open(tmp_path, "wb") as f:
8
- f.write(contents)
9
-
10
- caption = generate_caption(tmp_path)
11
-
12
- # Generate audio
13
- audio_path = os.path.join(tempfile.gettempdir(), file.filename + ".mp3")
14
- tts = gTTS(text=caption)
15
- tts.save(audio_path)
16
-
17
- return JSONResponse({
18
  "answer": caption,
19
- "audio": f"/files/{os.path.basename(audio_path)}"
20
- })
21
-
22
  except Exception as e:
23
- return JSONResponse({"error": str(e)}, status_code=500)
 
 
 
 
1
  @app.post("/imagecaption/")
2
+ async def caption_from_frontend(file: UploadFile = File(...)):
3
  try:
4
+ # Process image and generate caption
5
+ caption = "This would be your generated image caption"
6
+ audio_path = "/files/caption_audio.mp3" # Generated audio path
7
+
8
+ return {
 
 
 
 
 
 
 
 
 
9
  "answer": caption,
10
+ "audio": audio_path
11
+ }
 
12
  except Exception as e:
13
+ return JSONResponse(
14
+ {"detail": str(e)},
15
+ status_code=500
16
+ )