File size: 1,728 Bytes
ef906b4
 
d16f617
ef906b4
d16f617
ef906b4
 
d16f617
ef906b4
 
d16f617
ef906b4
 
 
d16f617
ef906b4
 
d16f617
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from huggingface_hub import InferenceClient
import gradio as gr

# Настраиваем HF‑клиент
HF_TOKEN = os.getenv("HF_HUB_TOKEN")
if not HF_TOKEN:
    raise RuntimeError("Не задан HF_HUB_TOKEN в настройках Space")
client = InferenceClient(token=HF_TOKEN)

def generate_bpmn(description: str) -> str:
    prompt = (
        "You are a BPMN 2.0 XML generator.\n"
        "Given this plain-text process description:\n"
        f"{description}\n"
        "Output ONLY valid BPMN 2.0 XML, without any extra text."
    )
    # Вызываем HF Inference API (без FastAPI)
    result = client.text_generation(
        prompt,
        model="ministral/Ministral-3b-instruct",
        max_new_tokens=1024,
        temperature=0.0,
        do_sample=False,
        details=True
    )
    xml = result[0].generated_text
    # отрезаем всё до <definitions>
    if "<definitions" in xml:
        xml = xml[xml.index("<definitions"):]
    return xml

# Собираем Gradio‑интерфейс
with gr.Blocks() as demo:
    gr.Markdown("## Генератор BPMN 2.0 XML на основе текста")
    inp = gr.Textbox(
        lines=5,
        placeholder="Опиши процесс: «Клиент подаёт заявку, …»",
        label="Описание процесса"
    )
    out = gr.Textbox(lines=15, label="BPMN 2.0 XML")
    btn = gr.Button("Сгенерировать BPMN")
    btn.click(fn=generate_bpmn, inputs=inp, outputs=out)

# HF Spaces поднимет это автоматически, порт подхватится из окружения
demo.launch(
    server_name="0.0.0.0",
    server_port=int(os.environ.get("PORT", 7860))
)