Spaces:
Sleeping
Sleeping
Update appImage.py
Browse files- 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 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
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":
|
20 |
-
}
|
21 |
-
|
22 |
except Exception as e:
|
23 |
-
return JSONResponse(
|
|
|
|
|
|
|
|
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 |
+
)
|