Spaces:
Runtime error
Runtime error
์ฃผ์ commited on
Commit ยท
2a61705
1
Parent(s): 5a15d75
Fix BASE_DIR path for data loading
Browse files- app/main.py +10 -16
app/main.py
CHANGED
|
@@ -8,23 +8,24 @@ app = FastAPI()
|
|
| 8 |
|
| 9 |
@app.get("/test_random")
|
| 10 |
def test_random_file():
|
| 11 |
-
|
| 12 |
-
audio_dir = "data/source_data"
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
candidates = [f for f in os.listdir(audio_dir) if f.endswith(".wav")]
|
| 15 |
if not candidates:
|
| 16 |
-
return {"error": "No .wav files found
|
| 17 |
|
| 18 |
chosen_file = random.choice(candidates)
|
| 19 |
audio_path = os.path.join(audio_dir, chosen_file)
|
| 20 |
|
| 21 |
-
# ์ ์ฒด ํ์ดํ๋ผ์ธ
|
| 22 |
try:
|
| 23 |
whisper_text, first_kobart_text, second_kobart_text = run_pipeline(audio_path)
|
| 24 |
except Exception as e:
|
| 25 |
return {"error": str(e)}
|
| 26 |
|
| 27 |
-
# ๊ฒฐ๊ณผ ๋ฐํ
|
| 28 |
return {
|
| 29 |
"filename": chosen_file,
|
| 30 |
"whisper_result": whisper_text,
|
|
@@ -32,24 +33,17 @@ def test_random_file():
|
|
| 32 |
"second_kobart_result": second_kobart_text
|
| 33 |
}
|
| 34 |
|
| 35 |
-
|
| 36 |
@app.post("/inference")
|
| 37 |
async def inference(audio: UploadFile=File(...)):
|
| 38 |
# ํ์ผ ์ ์ฅ
|
| 39 |
os.makedirs("temp", exist_ok=True)
|
| 40 |
-
audio_path = f"temp/{audio.filename}"
|
|
|
|
| 41 |
with open(audio_path, "wb") as f:
|
| 42 |
f.write(await audio.read())
|
| 43 |
|
| 44 |
-
# ๋ชจ๋ธ ์ถ๋ก
|
| 45 |
try:
|
| 46 |
whisper_text, first_kobart_text, second_kobart_text = run_pipeline(audio_path)
|
| 47 |
except Exception as e:
|
| 48 |
-
return
|
| 49 |
-
|
| 50 |
-
# ๊ฒฐ๊ณผ ๋ฐํ
|
| 51 |
-
return {
|
| 52 |
-
"whisper_result": whisper_text,
|
| 53 |
-
"first_kobart_result": first_kobart_text,
|
| 54 |
-
"second_kobart_result": second_kobart_text
|
| 55 |
-
}
|
|
|
|
| 8 |
|
| 9 |
@app.get("/test_random")
|
| 10 |
def test_random_file():
|
| 11 |
+
BASE_DIR = "/Users/juyeong/Desktop/2025-01/jeju_potato"
|
| 12 |
+
audio_dir = os.path.join(BASE_DIR, "data/source_data")
|
| 13 |
+
|
| 14 |
+
if not os.path.exists(audio_dir):
|
| 15 |
+
return {"error": f"Directory not found: {audio_dir}"}
|
| 16 |
|
| 17 |
candidates = [f for f in os.listdir(audio_dir) if f.endswith(".wav")]
|
| 18 |
if not candidates:
|
| 19 |
+
return {"error": "No .wav files found"}
|
| 20 |
|
| 21 |
chosen_file = random.choice(candidates)
|
| 22 |
audio_path = os.path.join(audio_dir, chosen_file)
|
| 23 |
|
|
|
|
| 24 |
try:
|
| 25 |
whisper_text, first_kobart_text, second_kobart_text = run_pipeline(audio_path)
|
| 26 |
except Exception as e:
|
| 27 |
return {"error": str(e)}
|
| 28 |
|
|
|
|
| 29 |
return {
|
| 30 |
"filename": chosen_file,
|
| 31 |
"whisper_result": whisper_text,
|
|
|
|
| 33 |
"second_kobart_result": second_kobart_text
|
| 34 |
}
|
| 35 |
|
| 36 |
+
|
| 37 |
@app.post("/inference")
|
| 38 |
async def inference(audio: UploadFile=File(...)):
|
| 39 |
# ํ์ผ ์ ์ฅ
|
| 40 |
os.makedirs("temp", exist_ok=True)
|
| 41 |
+
audio_path = f"temp/{audio.filename}" # ํด๋ผ์ด์ธํธ๋ก๋ถํฐ ๋ฐ์ ์์ฑํ์ผ ์ ์ฅ
|
| 42 |
+
|
| 43 |
with open(audio_path, "wb") as f:
|
| 44 |
f.write(await audio.read())
|
| 45 |
|
|
|
|
| 46 |
try:
|
| 47 |
whisper_text, first_kobart_text, second_kobart_text = run_pipeline(audio_path)
|
| 48 |
except Exception as e:
|
| 49 |
+
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|