import gradio as gr from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig import torch import spaces # <-- правильный импорт (пакет spaces) MODEL = "covaga/eplan-assistant-v3-merged" print("Loading model...") tokenizer = AutoTokenizer.from_pretrained(MODEL) quant_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16, ) model = AutoModelForCausalLM.from_pretrained( MODEL, device_map="auto", quantization_config=quant_config, ) print("Model loaded.") @spaces.GPU # <-- используем декоратор из пакета spaces def respond(message, history): messages = [{"role": "user", "content": message}] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt" ).to(model.device) outputs = model.generate( **inputs, max_new_tokens=512, do_sample=True, temperature=0.7 ) answer = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True) return answer demo = gr.ChatInterface( fn=respond, title="EPLAN Assistant", description="Вопросы по EPLAN Electric 2026" ) demo.launch()