Spaces:
Build error
Build error
Update app.py
Browse files123453 unmodified lines91011121314151617181920212213 unmodified lines36373839404142434445465 unmodified lines52535455565766 unmodified lines124125126127128129130import osimport timeimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizerimport gradio as gr3 unmodified linesMODEL_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>"""13 unmodified linesmodel = AutoModelForCausalLM.from_pretrained(MODEL_ID,torch_dtype=torch.bfloat16,low_cpu_mem_usage=True,trust_remote_code=True)tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)def stream_chat(message: str,history: list,5 unmodified lines):print(f'message: {message}')print(f'history: {history}')resp, history = model.chat(tokenizer,query = message,66 unmodified lines["Tell me a random fun fact about the Roman Empire."],["Show me a code snippet of a website's sticky header in CSS and JavaScript."],],cache_examples="lazy",)1234563 unmodified lines101112131415161718192021222313 unmodified lines3738394041424344454647485 unmodified lines5455565758596066 unmodified lines127128129130131132133import osimport timeimport spacesimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizerimport gradio as gr3 unmodified linesMODEL_ID = os.environ.get("MODEL_ID", None)MODEL_NAME = MODEL_ID.split("/")[-1]TITLE = "<h1><center>MiniCPM-S-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 with only 1.2B parameters excluding embeddings.</p></center>"""13 unmodified linesmodel = AutoModelForCausalLM.from_pretrained(MODEL_ID,torch_dtype=torch.bfloat16,device_map='auto',low_cpu_mem_usage=True,trust_remote_code=True)tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)@spaces.GPU()def stream_chat(message: str,history: list,5 unmodified lines):print(f'message: {message}')print(f'history: {history}')torch.manual_seed(0)resp, history = model.chat(tokenizer,query = message,66 unmodified lines["Tell me a random fun fact about the Roman Empire."],["Show me a code snippet of a website's sticky header in CSS and JavaScript."],],cache_examples=False,)
app.py+7-4