Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI, UploadFile, File | |
| from fastapi.responses import JSONResponse | |
| from app.inference import run_pipeline | |
| import os | |
| import random | |
| app = FastAPI() | |
| 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 | |
| } | |
| 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)} | |