Spaces:
Build error
Build error
Update app.py
Browse files12345678910111213141514 unmodified lines3031323334353637383940414243444546474849502 unmodified lines535455565758597 unmodified lines6768697071727374757677787980818271 unmodified lines154155156157158159160161162163164165import osimport time#import spacesimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamerimport gradio as grfrom threading import ThreadMODEL_LIST = ["HuggingFaceTB/SmolLM-1.7B-Instruct", "HuggingFaceTB/SmolLM-135M-Instruct", "HuggingFaceTB/SmolLM-360M-Instruct"]HF_TOKEN = os.environ.get("HF_TOKEN", None)TITLE = "<h1><center>SmolLM-Instruct</center></h1>"PLACEHOLDER = """<center>14 unmodified lines}"""# pip install transformersfrom transformers import AutoModelForCausalLM, AutoTokenizerdevice = "cpu" # for GPU usage or "cpu" for CPU usagetokenizer0 = AutoTokenizer.from_pretrained(MODEL_LIST[0])model0 = AutoModelForCausalLM.from_pretrained(MODEL_LIST[0]).to(device)tokenizer1 = AutoTokenizer.from_pretrained(MODEL_LIST[1])model1 = AutoModelForCausalLM.from_pretrained(MODEL_LIST[1]).to(device)tokenizer2 = AutoTokenizer.from_pretrained(MODEL_LIST[2])model2 = AutoModelForCausalLM.from_pretrained(MODEL_LIST[2]).to(device)#@spaces.GPU()def stream_chat(message: str,history: list,2 unmodified linestop_p: float = 1.0,top_k: int = 20,penalty: float = 1.2,choice: str = "135M"):print(f'message: {message}')print(f'history: {history}')7 unmodified linesconversation.append({"role": "user", "content": message})if choice == "1.7B":tokenizer = tokenizer0model = model0elif choice == "135M":model = model1tokenizer = tokenizer1else:model = model2tokenizer = tokenizer2input_text=tokenizer.apply_chat_template(conversation, tokenize=False)inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)71 unmodified lineslabel="Repetition penalty",render=False,),gr.Radio(["135M", "360M", "1.7B"],value="135M",label="Load Model",render=False,),],examples=[["Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option."],1234567891011121314151614 unmodified lines3132333435363738394041422 unmodified lines4546474849507 unmodified lines58596061626371 unmodified lines135136137138139140import osimport timeimport spacesimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamerimport gradio as grfrom threading import ThreadMODEL_LIST = ["mistralai/Mistral-Nemo-Instruct-2407"]HF_TOKEN = os.environ.get("HF_TOKEN", None)MODEL = os.environ.get("MODEL_ID")TITLE = "<h1><center>Mistral-Nemo</center></h1>"PLACEHOLDER = """<center>14 unmodified lines}"""device = "cuda" # for GPU usage or "cpu" for CPU usagetokenizer = AutoTokenizer.from_pretrained(MODEL)model = AutoModelForCausalLM.from_pretrained(MODEL).to(device)@spaces.GPU()def stream_chat(message: str,history: list,2 unmodified linestop_p: float = 1.0,top_k: int = 20,penalty: float = 1.2,):print(f'message: {message}')print(f'history: {history}')7 unmodified linesconversation.append({"role": "user", "content": message})input_text=tokenizer.apply_chat_template(conversation, tokenize=False)inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)71 unmodified lineslabel="Repetition penalty",render=False,),],examples=[["Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option."],
app.py+8-33