Spaces:
Sleeping
Sleeping
Download app.py from mrfirdauss/speech2text: direct link, hf CLI and curl.
- Browser
- Download file 866 Bytes
-
https://huggingface.co/spaces/mrfirdauss/speech2text/resolve/main/app.py
- Command line
-
hf download hf://spaces/mrfirdauss/speech2text/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mrfirdauss/speech2text/resolve/main/app.py
866 Bytes
| import os | |
| from fastapi import FastAPI, HTTPException | |
| from io import BytesIO | |
| import requests | |
| from models import InsertedLink, ExtractedText | |
| import extractor | |
| os.environ['TRANSFORMERS_CACHE'] = '/transformers_cache' | |
| os.environ['HF_HOME'] = '/transformers_cache' | |
| app = FastAPI() | |
| def getall(): | |
| return {"hello":"world"} | |
| async def extract(link: InsertedLink): | |
| response = requests.get(link.link) | |
| if response.status_code == 200: | |
| # Open the PDF from bytes in memory | |
| mp3 = (BytesIO(response.content)) | |
| else: | |
| #return error, make 500 because file server error | |
| raise HTTPException(status_code=response.status_code, detail="File server error") | |
| dictresult = extractor.speech2text(mp3) | |
| return ExtractedText(**dictresult) |