Aleksandr Evteev commited on
Commit
ef906b4
·
1 Parent(s): 065c785

Add base logic

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +43 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .idea/
2
+ .venv/
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI, HTTPException
3
+ from pydantic import BaseModel
4
+ from huggingface_hub import InferenceClient
5
+
6
+ class GenerateRequest(BaseModel):
7
+ description: str
8
+
9
+ app = FastAPI()
10
+
11
+ HF_TOKEN = os.getenv("HF_HUB_TOKEN")
12
+ if not HF_TOKEN:
13
+ raise RuntimeError("Не задан HF_HUB_TOKEN")
14
+
15
+ client = InferenceClient(token=HF_TOKEN)
16
+
17
+ @app.post("/generate-bpmn", response_model=str)
18
+ async def generate_bpmn(req: GenerateRequest):
19
+ prompt = (
20
+ "You are a BPMN 2.0 XML generator.\n"
21
+ "Given this plain-text process description:\n"
22
+ f"{req.description}\n"
23
+ "Output ONLY valid BPMN 2.0 XML, without any extra text."
24
+ )
25
+ try:
26
+ result = client.text_generation(
27
+ prompt,
28
+ model="ministral/Ministral-3b-instruct",
29
+ max_new_tokens=1024,
30
+ temperature=0.0,
31
+ do_sample=False,
32
+ details=True
33
+ )
34
+ except Exception as e:
35
+ raise HTTPException(status_code=500, detail=f"Inference API error: {e}")
36
+
37
+ # Теперь result[0] — объект с полем generated_text
38
+ text = result[0].generated_text
39
+
40
+ if "<definitions" in text:
41
+ text = text[text.index("<definitions"):]
42
+
43
+ return text
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ huggingface-hub>=0.14.1