|
|
| import os
|
| import uvicorn
|
| from fastapi import FastAPI
|
| from pydantic import BaseModel
|
|
|
|
|
| os.environ['HF_HOME'] = '/tmp/huggingface'
|
| os.environ['TRANSFORMERS_CACHE'] = '/tmp/huggingface'
|
| os.environ['HUGGINGFACE_HUB_CACHE'] = '/tmp/huggingface'
|
|
|
|
|
| os.makedirs('/tmp/huggingface', exist_ok=True)
|
|
|
|
|
| from agents import TutorAgent, BioUser
|
|
|
|
|
| app = FastAPI(title="Bioinformatics Tutor API")
|
|
|
|
|
| try:
|
| user_agent = BioUser()
|
| tutor_agent = TutorAgent()
|
| agents_loaded = True
|
| except Exception as e:
|
| print(f"Error loading agents: {e}")
|
| agents_loaded = False
|
|
|
|
|
| class QueryRequest(BaseModel):
|
| question: str
|
|
|
|
|
| class QueryResponse(BaseModel):
|
| answer: str
|
|
|
| @app.post("/ask", response_model=QueryResponse)
|
| def ask_tutor(request: QueryRequest):
|
| """
|
| Ask the Bioinformatics Tutor a question.
|
| """
|
| if not agents_loaded:
|
| return QueryResponse(answer="Error: Agents not loaded. Please check the server logs.")
|
|
|
| try:
|
| answer = tutor_agent.process_query(request.question)
|
| return QueryResponse(answer=answer)
|
| except Exception as e:
|
| return QueryResponse(answer=f"Error processing query: {str(e)}")
|
|
|
| @app.get("/")
|
| def root():
|
| return {"message": "Bioinformatics Tutor API is running.", "agents_loaded": agents_loaded}
|
|
|
| @app.get("/health")
|
| def health_check():
|
| return {"status": "healthy", "agents_loaded": agents_loaded}
|
|
|