์ฃผ์˜
Fix BASE_DIR path for data loading
2a61705
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import JSONResponse
from app.inference import run_pipeline
import os
import random
app = FastAPI()
@app.get("/test_random")
def test_random_file():
BASE_DIR = "/Users/juyeong/Desktop/2025-01/jeju_potato"
audio_dir = os.path.join(BASE_DIR, "data/source_data")
if not os.path.exists(audio_dir):
return {"error": f"Directory not found: {audio_dir}"}
candidates = [f for f in os.listdir(audio_dir) if f.endswith(".wav")]
if not candidates:
return {"error": "No .wav files found"}
chosen_file = random.choice(candidates)
audio_path = os.path.join(audio_dir, chosen_file)
try:
whisper_text, first_kobart_text, second_kobart_text = run_pipeline(audio_path)
except Exception as e:
return {"error": str(e)}
return {
"filename": chosen_file,
"whisper_result": whisper_text,
"first_kobart_result": first_kobart_text,
"second_kobart_result": second_kobart_text
}
@app.post("/inference")
async def inference(audio: UploadFile=File(...)):
# ํŒŒ์ผ ์ €์žฅ
os.makedirs("temp", exist_ok=True)
audio_path = f"temp/{audio.filename}" # ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์Œ์„ฑํŒŒ์ผ ์ €์žฅ
with open(audio_path, "wb") as f:
f.write(await audio.read())
try:
whisper_text, first_kobart_text, second_kobart_text = run_pipeline(audio_path)
except Exception as e:
return {"error": str(e)}