Download main.py from Teotonix/MaindAI: direct link, hf CLI and curl.
- Browser
- Download file 607 Bytes
-
https://huggingface.co/spaces/Teotonix/MaindAI/resolve/main/main.py
- Command line
-
hf download hf://spaces/Teotonix/MaindAI/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Teotonix/MaindAI/resolve/main/main.py
607 Bytes
| from fastapi import FastAPI, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import requests | |
| app = FastAPI() | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| OLLAMA_URL = "http://127.0.0.1:11434/api/generate" | |
| async def chat(req: Request): | |
| data = await req.json() | |
| prompt = data.get("message", "") | |
| r = requests.post(OLLAMA_URL, json={ | |
| "model": "mistral", | |
| "prompt": prompt, | |
| "stream": False | |
| }, timeout=120) | |
| j = r.json() | |
| return {"reply": j.get("response", "")} | |