Download app.py from humut/CAD_LLM3: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/humut/CAD_LLM3/resolve/main/app.py
- Command line
-
hf download hf://humut/CAD_LLM3/app.py
-
curl -L -o app.py https://huggingface.co/humut/CAD_LLM3/resolve/main/app.py
1.78 kB
| """CAD_LLM3 — HF Space Proxy: humut/CAD_LLM3 | |
| Űripar + precíziós modellek""" | |
| import os, json, httpx | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| app = FastAPI(title="CAD_LLM3") | |
| app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]) | |
| HF_SPACE = os.getenv("HF_SPACE", "humut/CAD_LLM3") | |
| HF_TOKEN = os.getenv("HF_TOKEN", "") | |
| MODEL_NAME = os.getenv("MODEL_NAME", "cad_llm3") | |
| with open("config.json") as f: CONFIG = json.load(f) | |
| class ChatRequest(BaseModel): | |
| message: str | |
| history: list[dict] = [] | |
| async def health(): | |
| return {"status": "ok", "model": MODEL_NAME, "hf_space": HF_SPACE} | |
| async def config(): return CONFIG | |
| async def chat(req: ChatRequest): | |
| if not HF_TOKEN: | |
| return {"response": f"[{MODEL_NAME}] No HF_TOKEN configured", "dsl": ""} | |
| try: | |
| async with httpx.AsyncClient(timeout=120) as client: | |
| resp = await client.post( | |
| f"https://api-inference.huggingface.co/models/{HF_SPACE}", | |
| headers={"Authorization": f"Bearer {HF_TOKEN}"}, | |
| json={"inputs": req.message, "parameters": {"max_new_tokens": 512, "temperature": 0.7}}) | |
| if resp.status_code == 200: | |
| data = resp.json() | |
| raw = data[0].get("generated_text", "") if isinstance(data, list) else str(data) | |
| return {"response": raw, "model": MODEL_NAME} | |
| except Exception as e: | |
| return {"response": f"[{MODEL_NAME}] Error: {e}", "dsl": ""} | |
| return {"response": f"[{MODEL_NAME}] No response", "dsl": ""} | |
| if __name__ == "__main__": | |
| import uvicorn; uvicorn.run(app, host="0.0.0.0", port=8000) |