From 8683ef478a672859485914cfbca4fbcd35819c9a Mon Sep 17 00:00:00 2001
From: Subliminal Guy <subliminal_kid@posteo.de>
Date: Wed, 23 Apr 2025 13:55:53 +0000
Subject: [PATCH] Add FilePath Handling Update gitignore and dockerignore

---
 .dockerignore     |  3 ++-
 .gitignore        |  2 ++
 app/webservice.py | 20 +++++++++++++++++---
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/.dockerignore b/.dockerignore
index 59e2f83..d578562 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,3 +1,4 @@
 .git
 .venv
-venv
\ No newline at end of file
+venv
+/audio_files
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 35e5869..537f535 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,3 +42,5 @@ pip-wheel-metadata
 poetry/core/*
 
 public
+
+/audio_files
diff --git a/app/webservice.py b/app/webservice.py
index d0c39b9..c12a651 100644
--- a/app/webservice.py
+++ b/app/webservice.py
@@ -1,5 +1,6 @@
 import importlib.metadata
 import os
+import io
 from os import path
 from typing import Annotated, Optional, Union
 from urllib.parse import quote
@@ -54,8 +55,9 @@ async def index():
 
 
 @app.post("/asr", tags=["Endpoints"])
+
 async def asr(
-    audio_file: UploadFile = File(...),  # noqa: B008
+    file_name: str = Query(..., description="path to Audio or video file to transcribe"),
     encode: bool = Query(default=True, description="Encode audio first through ffmpeg"),
     task: Union[str, None] = Query(default="transcribe", enum=["transcribe", "translate"]),
     language: Union[str, None] = Query(default=None, enum=LANGUAGE_CODES),
@@ -89,9 +91,21 @@ async def asr(
     ),
     output: Union[str, None] = Query(default="txt", enum=["txt", "vtt", "srt", "tsv", "json"]),
 ):
+
+    print("filename", file_name)
+    # Get the current working directory
+    current_directory = os.getcwd()
+    # construct file path
+    audio_path = os.path.join(f'{current_directory}/audio_files', file_name)
+
+    # Print the current working directory
+    print("file path", audio_path)
+
     # Run transcription in a background thread to keep the event loop responsive
     def _run_transcription():
-        audio = load_audio(audio_file.file, encode)
+
+        audio = load_audio(open(audio_path, 'rb'), encode)
+
         return asr_model.transcribe(
             audio,
             task,
@@ -110,7 +124,7 @@ async def asr(
         media_type="text/plain",
         headers={
             "Asr-Engine": CONFIG.ASR_ENGINE,
-            "Content-Disposition": f'attachment; filename="{quote(audio_file.filename)}.{output}"',
+            "Content-Disposition": f'attachment; filename="{quote(file_name)}.{output}"',
         },
     )
 
-- 
GitLab