Spaces:
Sleeping
Sleeping
Download app.py from Aleznaor/Optimus-AI: direct link, hf CLI and curl.
- Browser
- Download file 965 Bytes
-
https://huggingface.co/spaces/Aleznaor/Optimus-AI/resolve/main/app.py
- Command line
-
hf download hf://spaces/Aleznaor/Optimus-AI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Aleznaor/Optimus-AI/resolve/main/app.py
965 Bytes
| import os | |
| import time | |
| import subprocess | |
| import requests | |
| from fastapi import FastAPI, Header, HTTPException | |
| from pydantic import BaseModel | |
| app = FastAPI() | |
| SAFE_API_KEY = os.environ.get("atulsinhatilkut") | |
| class OllamaRequest(BaseModel): | |
| model: str | |
| prompt: str | |
| stream: bool = False | |
| def startup_event(): | |
| # Start Ollama and create your custom model | |
| subprocess.Popen(["ollama", "serve"]) | |
| time.sleep(10) # Give it 10 seconds to wake up | |
| subprocess.run(["ollama", "create", "optimus", "-f", "Modelfile"]) | |
| async def generate(request: OllamaRequest, authorization: str = Header(None)): | |
| if authorization != f"Bearer {SAFE_API_KEY}": | |
| raise HTTPException(status_code=401, detail="Unauthorized") | |
| response = requests.post("http://localhost:11434/api/generate", json=request.dict()) | |
| return response.json() | |
| def health(): | |
| return {"status": "Optimus is Online"} |