Spaces:
Sleeping
Sleeping
Download main.py from anbu2243/api-bepflow: direct link, hf CLI and curl.
- Browser
- Download file 887 Bytes
-
https://huggingface.co/spaces/anbu2243/api-bepflow/resolve/main/main.py
- Command line
-
hf download hf://spaces/anbu2243/api-bepflow/main.py
-
curl -L -o main.py https://huggingface.co/spaces/anbu2243/api-bepflow/resolve/main/main.py
887 Bytes
| import os | |
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from huggingface_hub import InferenceClient | |
| app = FastAPI() | |
| client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct", token=os.getenv("HF_TOKEN")) | |
| class GenerateRequest(BaseModel): | |
| prompt: str | |
| engine: str = "mermaid" | |
| def read_root(): | |
| return {"status": "Bepflow Engine Online"} | |
| def generate(req: GenerateRequest): | |
| system_instr = f"Act as Bepflow Omni-Architect. Output ONLY raw {req.engine} code." | |
| try: | |
| out = client.chat_completion( | |
| messages=[{"role": "system", "content": system_instr}, {"role": "user", "content": req.prompt}], | |
| max_tokens=1500 | |
| ) | |
| return {"text": out.choices[0].message.content.strip().replace("```mermaid", "").replace("```", "")} | |
| except Exception as e: | |
| return {"error": str(e)} |