drrobot9's picture
push updated backend changes and auto start buiding
6584be3 verified
# app.py
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'
# Create cache directory
os.makedirs('/tmp/huggingface', exist_ok=True)
from agents import TutorAgent, BioUser
# Initialize FastAPI
app = FastAPI(title="Bioinformatics Tutor API")
# Initialize agents
try:
user_agent = BioUser()
tutor_agent = TutorAgent()
agents_loaded = True
except Exception as e:
print(f"Error loading agents: {e}")
agents_loaded = False
# Request model
class QueryRequest(BaseModel):
question: str
# Response model
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}