llama, openCV를 자바에서 바로 사용 x
중간다리 역할 = FastAPI
내가 만든 모델을 웹 서버로 띄워서 자바에서 HTTP요청 보내기
ex) 서버 생성
from fastapi import FastAPI
app = FastAPI()
# 학습된 모델 불러오기 (예: LLaMA + OpenCV)
model = load_your_model()
@app.post("/predict")
def predict(image_url: str):
# 1. OpenCV로 이미지 처리
img = cv2.imread(image_url)
# 2. LLaMA로 설명 생성
result = model.predict(img)
return {"result": result}
서버 실행
`uvicorn server:app --reload`
자바 코드 예시
import org.springframework.web.client.RestTemplate;
public class Main {
public static void main(String[] args) {
RestTemplate restTemplate = new RestTemplate();
String url = "<http://localhost:8000/predict?image_url=고양이.jpg>";
String result = restTemplate.getForObject(url, String.class);
System.out.println(result); // 결과 출력
}
}
즉 자바는 API주소로 HTPP요청만 보내면됨
이걸 서버를 사용하던지 라즈베리파이 사용하면 될 듯?