Spaces:
Build error
Build error
File size: 2,642 Bytes
9b9d44e eda02a7 f6b1133 eda02a7 f6b1133 eda02a7 f6b1133 eda02a7 f6b1133 eda02a7 9b9d44e eda02a7 9b9d44e eda02a7 f6b1133 eda02a7 f6b1133 eda02a7 f6b1133 9b9d44e f6b1133 eda02a7 f6b1133 eda02a7 9b9d44e eda02a7 f6b1133 eda02a7 f6b1133 eda02a7 f6b1133 eda02a7 f6b1133 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# ./backend/app/main.py
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
import os
from pydantic import BaseModel
from youtube_parser import process_youtube_video_data
from rag_core import perform_rag_and_generate # 수정된 함수를 임포트
app = FastAPI()
# CORS 설정
origins = [
"http://localhost:8080",
"http://localhost:5173",
"https://sodagraph-po.hf.space",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 경로 설정
current_file_dir = os.path.dirname(os.path.abspath(__file__))
project_root_dir = os.path.join(current_file_dir, "..", "..")
static_files_dir = os.path.join(project_root_dir, "static")
class VideoProcessRequest(BaseModel):
video_url: str
query: str
ollama_model_name: str = "hf.co/DevQuasar/naver-hyperclovax.HyperCLOVAX-SEED-Text-Instruct-0.5B-GGUF:F16"
# ✅ 유튜브 영상 처리 API
@app.post("/api/process_youtube_video")
async def process_youtube_video(request: VideoProcessRequest):
try:
# 1. 유튜브 영상에서 자막/콘텐츠 추출
processed_chunks_with_timestamps = await process_youtube_video_data(request.video_url)
if not processed_chunks_with_timestamps:
return {"message": "자막 또는 내용을 추출할 수 없습니다.", "results": []}
# 2. RAG 프로세스 실행 (검색 + 생성)
rag_result = await perform_rag_and_generate(
query=request.query,
chunks_with_timestamps=processed_chunks_with_timestamps,
ollama_model_name=request.ollama_model_name,
top_k=50
)
# 3. 최종 결과 반환
return {
**rag_result, # rag_core에서 반환된 결과 딕셔너리를 그대로 사용
"video_url": request.video_url,
"query": request.query,
"ollama_model_used": request.ollama_model_name,
}
except Exception as e:
print(f"ERROR: 서버 처리 중 오류 발생: {str(e)}")
# 실제 Exception의 세부 정보를 로깅하는 것이 좋음
raise HTTPException(status_code=500, detail=f"서버 처리 중 오류가 발생했습니다: {e}")
# ✅ 정적 파일은 마지막에 mount
app.mount("/", StaticFiles(directory=static_files_dir, html=True), name="static")
# 서버 실행을 위한 메인 진입점
if __name__ == "__main__":
import uvicorn
port = int(os.environ.get("PORT", 7860))
uvicorn.run(app, host="0.0.0.0", port=port)
|