forked from open-webui/open-webui
		
	Migrate to python logging module with env var control.
This commit is contained in:
		
							parent
							
								
									d865b9fe59
								
							
						
					
					
						commit
						e6dd0bfbe0
					
				
					 15 changed files with 174 additions and 82 deletions
				
			
		|  | @ -1,4 +1,5 @@ | |||
| import os | ||||
| import logging | ||||
| from fastapi import ( | ||||
|     FastAPI, | ||||
|     Request, | ||||
|  | @ -21,7 +22,10 @@ from utils.utils import ( | |||
| ) | ||||
| from utils.misc import calculate_sha256 | ||||
| 
 | ||||
| from config import CACHE_DIR, UPLOAD_DIR, WHISPER_MODEL, WHISPER_MODEL_DIR | ||||
| from config import SRC_LOG_LEVELS, CACHE_DIR, UPLOAD_DIR, WHISPER_MODEL, WHISPER_MODEL_DIR | ||||
| 
 | ||||
| log = logging.getLogger(__name__) | ||||
| log.setLevel(SRC_LOG_LEVELS["AUDIO"]) | ||||
| 
 | ||||
| app = FastAPI() | ||||
| app.add_middleware( | ||||
|  | @ -38,7 +42,7 @@ def transcribe( | |||
|     file: UploadFile = File(...), | ||||
|     user=Depends(get_current_user), | ||||
| ): | ||||
|     print(file.content_type) | ||||
|     log.info(f"file.content_type: {file.content_type}") | ||||
| 
 | ||||
|     if file.content_type not in ["audio/mpeg", "audio/wav"]: | ||||
|         raise HTTPException( | ||||
|  | @ -62,7 +66,7 @@ def transcribe( | |||
|         ) | ||||
| 
 | ||||
|         segments, info = model.transcribe(file_path, beam_size=5) | ||||
|         print( | ||||
|         log.info( | ||||
|             "Detected language '%s' with probability %f" | ||||
|             % (info.language, info.language_probability) | ||||
|         ) | ||||
|  | @ -72,7 +76,7 @@ def transcribe( | |||
|         return {"text": transcript.strip()} | ||||
| 
 | ||||
|     except Exception as e: | ||||
|         print(e) | ||||
|         log.exception(e) | ||||
| 
 | ||||
|         raise HTTPException( | ||||
|             status_code=status.HTTP_400_BAD_REQUEST, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Self Denial
						Self Denial