์ฃผ์˜ commited on
Commit
2a61705
ยท
1 Parent(s): 5a15d75

Fix BASE_DIR path for data loading

Browse files
Files changed (1) hide show
  1. 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
- # data/source_data์—์„œ ๋žœ๋ค์œผํฌ ํŒŒ์ผ ํ•˜๋‚˜ ์„ ํƒ
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 in data/source_data"}
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
- # ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ์Œ์„ฑํŒŒ์ผ์„ Form-data ํ˜•์‹์œผ๋กœ ๋ฐ›์Œ
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}" # ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์Œ์„ฑํŒŒ์ผ์„ temp/ ํด๋”์— ์ €์žฅ
 
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 JSONResponse(status_code=500, content={"error": str(e)})
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)}