Spaces:
Running on Zero
Running on Zero
File size: 1,493 Bytes
7eece4b 6dd48b2 c84fccb 7eece4b c84fccb 7eece4b c84fccb 6dd48b2 7eece4b c84fccb 6dd48b2 7eece4b 6dd48b2 c84fccb 6dd48b2 c84fccb 6dd48b2 c84fccb 6dd48b2 c84fccb 6dd48b2 c84fccb 6dd48b2 c84fccb | 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 51 52 53 | import spaces
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL_ID = "Lev384501/qwen3-0.6b-russian-dialogues"
SEP = "\n### Ответ:\n"
print("Загружаю модель...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
dtype=torch.float16,
)
model = model.to("cuda")
print("Модель загружена.")
@spaces.GPU
def respond(message, history, max_tokens, temperature, top_p):
prompt = message.strip() + SEP
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
output = model.generate(
**inputs,
max_new_tokens=max_tokens,
temperature=temperature,
top_p=top_p,
do_sample=True,
repetition_penalty=1.3,
pad_token_id=tokenizer.eos_token_id,
)
generated = output[0][inputs["input_ids"].shape[1]:]
answer = tokenizer.decode(generated, skip_special_tokens=True).strip()
return answer
chatbot = gr.ChatInterface(
respond,
additional_inputs=[
gr.Slider(minimum=1, maximum=256, value=80, step=1, label="Max new tokens"),
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
],
title="Qwen3-0.6B Russian Dialogues",
)
if __name__ == "__main__":
chatbot.launch() |