Spaces:
Build error
Build error
Update app.py
Browse files123456789101112131415161718192021222312 unmodified lines363738394041424344454647485 unmodified lines545556575859606162636427 unmodified lines92939495969798import osimport timeimport spacesimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizerimport gradio as grMODEL_LIST = ["internlm/internlm2_5-7b-chat", "internlm/internlm2_5-7b-chat-1m"]HF_TOKEN = os.environ.get("HF_TOKEN", None)MODEL_ID = os.environ.get("MODEL_ID", None)MODEL_NAME = MODEL_ID.split("/")[-1]TITLE = "<h1><center>internlm2.5-7b-chat</center></h1>"DESCRIPTION = f"""<h3>MODEL NOW: <a href="https://hf.co/{MODEL_ID}">{MODEL_NAME}</a></h3>"""PLACEHOLDER = """<center><p>InternLM2.5 has open-sourced a 7 billion parameter base model<br> and a chat model tailored for practical scenarios.</p></center>"""12 unmodified linesmodel = AutoModelForCausalLM.from_pretrained(MODEL_ID,torch_dtype=torch.float16,trust_remote_code=True).cuda()tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)model = model.eval()@spaces.GPU()def stream_chat(message: str,history: list,5 unmodified lines):print(f'message: {message}')print(f'history: {history}')for resp, history in model.stream_chat(tokenizer,query = message,history = history,max_new_tokens = max_new_tokens,do_sample = False if temperature == 0 else True,top_p = top_p,top_k = top_k,27 unmodified linesmaximum=8192,step=1,value=1024,label="Max New Tokens",render=False,),gr.Slider(1234567891011121314151617181920212212 unmodified lines3536373839404142434445465 unmodified lines525354555657585960616227 unmodified lines90919293949596import osimport timeimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizerimport gradio as grMODEL_LIST = ["openbmb/MiniCPM-1B-sft-bf16", "openbmb/MiniCPM-S-1B-sft"]HF_TOKEN = os.environ.get("HF_TOKEN", None)MODEL_ID = os.environ.get("MODEL_ID", None)MODEL_NAME = MODEL_ID.split("/")[-1]TITLE = "<h1><center>MiniCPM-1B-chat</center></h1>"DESCRIPTION = f"""<h3>MODEL NOW: <a href="https://hf.co/{MODEL_ID}">{MODEL_NAME}</a></h3>"""PLACEHOLDER = """<center><p>MiniCPM is an End-Size LLM developed by ModelBest Inc. and TsinghuaNLP, with only 1.2B parameters excluding embeddings.</p></center>"""12 unmodified linesmodel = AutoModelForCausalLM.from_pretrained(MODEL_ID,torch_dtype=torch.bfloat16,device_map='auto',trust_remote_code=True)tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)def stream_chat(message: str,history: list,5 unmodified lines):print(f'message: {message}')print(f'history: {history}')for resp, history in model.chat(tokenizer,query = message,history = history,max_length = max_new_tokens,do_sample = False if temperature == 0 else True,top_p = top_p,top_k = top_k,27 unmodified linesmaximum=8192,step=1,value=1024,label="Max Length",render=False,),gr.Slider(
app.py+10-12