Delete app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192import osimport requestsfrom fastapi import FastAPI, Requestfrom fastapi.responses import JSONResponse, HTMLResponsefrom fastapi.templating import Jinja2Templates
# =========================# APP INIT# =========================
app = FastAPI(title="PyRunner Agent OS", version="3.0")
BASE_DIR = os.path.dirname(os.path.abspath(__file__))templates = Jinja2Templates(directory=os.path.join(BASE_DIR, "templates"))
# =========================# ENV# =========================
OLLAMA_URL = os.getenv("OLLAMA_URL", "http://localhost:11434")
MODELS = { "orchestrator": os.getenv("OLLAMA_MODEL", "qwen2.5:1.5b"), "coder": os.getenv("OLLAMA_CODE_MODEL", "qwen2.5-coder:1.5b"), "fast": os.getenv("OLLAMA_FAST_MODEL", "deepseek-coder:1.3b"), "fallback": os.getenv("OLLAMA_BACKUP_MODEL", "llama3.2:1b")}
# =========================# OLLAMA CORE CALL# =========================
def call_ollama(prompt, model): try: r = requests.post( f"{OLLAMA_URL}/api/generate", json={ "model": model, "prompt": prompt, "stream": False }, timeout=60 ) return r.json() except Exception as e: return {"error": str(e)}
# =========================# AGENT DEFINITIONS# =========================
def orchestrator_agent(user_input: str): """ Classifies task type """
prompt = f"""You are an orchestrator AI.
Classify this request into one category ONLY:
- code- vision- fashion- hairstyle- general
User request:{user_input}
Return ONLY the category name."""
res = call_ollama(prompt, MODELS["orchestrator"])
if "response" in res: return res["response"].strip().lower()
return "general"
def coder_agent(prompt): return call_ollama(prompt, MODELS["coder"])
def fashion_agent(prompt): system_prompt = f"""You are a fashion expert AI.Analyze outfit, styling, colors, trends.
User:{prompt}""" return call_ollama(system_prompt, MODELS["fast"])
def hairstyle_agent(prompt): system_prompt = f"""You are a barber & hairstyle expert.Describe hairstyle changes, fades, textures, transformations.
User:{prompt}""" return call_ollama(system_prompt, MODELS["fast"])
def fallback_agent(prompt): return call_ollama(prompt, MODELS["fallback"])
# =========================# ROUTER# =========================
def route_agent(category: str, prompt: str):
if category == "code": return coder_agent(prompt)
if category == "fashion": return fashion_agent(prompt)
if category == "hairstyle": return hairstyle_agent(prompt)
return fallback_agent(prompt)
# =========================# UI# =========================
@app.get("/", response_class=HTMLResponse)async def home(request: Request): return templates.TemplateResponse("index.html", {"request": request})
# =========================# HEALTH# =========================
@app.get("/health")def health(): return { "status": "ok", "agents": list(MODELS.keys()) }
# =========================# MAIN AGENT ENDPOINT# =========================
@app.post("/api/agent")async def agent(request: Request):
body = await request.json() user_input = body.get("prompt", "")
# 1. Decide agent category = orchestrator_agent(user_input)
# 2. Route to agent result = route_agent(category, user_input)
# 3. Fallback safety if "error" in result: result = fallback_agent(user_input)
return JSONResponse({ "category": category, "result": result })
# =========================# IMAGE PIPELINE HOOK (future)# =========================
@app.post("/api/image")async def image_pipeline(request: Request): body = await request.json()
return { "status": "queued", "pipeline": "vision_stub", "note": "Attach diffusion model later" }app.pyDeleted-192