Spaces:
Running
Running
Upload whisper.py
Browse files- whisper.py +25 -1
whisper.py
CHANGED
@@ -23,6 +23,16 @@ async def whsiper_to_text(file: UploadFile):
|
|
23 |
return None
|
24 |
return response.json()
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
@router.post("/akeno/whsiper")
|
27 |
async def whsiper_new(file: UploadFile = File(...)):
|
28 |
try:
|
@@ -35,4 +45,18 @@ async def whsiper_new(file: UploadFile = File(...)):
|
|
35 |
content={"status": "True", "message": response_data.get("text")}
|
36 |
)
|
37 |
except Exception as e:
|
38 |
-
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
return None
|
24 |
return response.json()
|
25 |
|
26 |
+
async def blip_image(file: UploadFile):
|
27 |
+
API_URL = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large"
|
28 |
+
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
29 |
+
contents = await file.read()
|
30 |
+
response = requests.post(API_URL, headers=headers, data=contents)
|
31 |
+
if response.status_code != 200:
|
32 |
+
print(f"Error status {response.status_code}")
|
33 |
+
return None
|
34 |
+
return response.json()
|
35 |
+
|
36 |
@router.post("/akeno/whsiper")
|
37 |
async def whsiper_new(file: UploadFile = File(...)):
|
38 |
try:
|
|
|
45 |
content={"status": "True", "message": response_data.get("text")}
|
46 |
)
|
47 |
except Exception as e:
|
48 |
+
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
49 |
+
|
50 |
+
@router.post("/akeno/blip-image-captioning-large", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
51 |
+
async def blip_images(file: UploadFile = File(...)):
|
52 |
+
try:
|
53 |
+
response_data = await blip_image(file)
|
54 |
+
if response_data is None:
|
55 |
+
raise HTTPException(status_code=400, detail="Failed to process the file")
|
56 |
+
|
57 |
+
return JSONResponse(
|
58 |
+
status_code=200,
|
59 |
+
content={"status": "True", "message": response_data}
|
60 |
+
)
|
61 |
+
except Exception as e:
|
62 |
+
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|