Spaces:
Sleeping
Sleeping
File size: 887 Bytes
b3387f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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"
@app.get("/")
def read_root():
return {"status": "Bepflow Engine Online"}
@app.post("/generate")
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)} |