Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines5678910111213141569 unmodified lines8586878889909192939495969798991001011021031041054 unmodified linesimport numpy as npimport jsonfrom transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamerimport gradio as gr# Применяем патч для streamingpatch_streaming()# === Настройки ===model_name = "Qwen/Qwen2.5-0.5B-Instruct"69 unmodified linesinputs = tokenizer(prompt, return_tensors="pt").to(model.device)streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)def generate():with torch.no_grad():model.generate(**inputs,max_new_tokens=256,temperature=0.7,streamer=streamer,use_cache=True)thread = threading.Thread(target=generate)thread.start()for text in streamer:yield text# === Gradio ===with gr.Blocks() as demo:4 unmodified lines567891011121369 unmodified lines83848586878889909192939495969798991001011021031041051061074 unmodified linesimport numpy as npimport jsonfrom transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamerfrom transformers_stream_generator import StreamingGenerationConfigimport gradio as gr# === Настройки ===model_name = "Qwen/Qwen2.5-0.5B-Instruct"69 unmodified linesinputs = tokenizer(prompt, return_tensors="pt").to(model.device)streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)# Используем специальную конфигурациюgeneration_config = StreamingGenerationConfig(max_new_tokens=256,temperature=0.7,top_p=0.9,do_sample=True)thread = threading.Thread(target=model.generate, kwargs={**inputs,"streamer": streamer,"generation_config": generation_config})thread.start()buffer = ""for token in streamer:buffer += tokenyield buffer# === Gradio ===with gr.Blocks() as demo:
app.py+17-15