Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505128 unmodified lines80818283848512 unmodified lines9899100101import gradio as grfrom huggingface_hub import InferenceClientfrom datasets import load_datasetfrom transformers import AutoTokenizer, AutoModelForCausalLMfrom transformers import Trainer, TrainingArgumentsmodel_name = "HuggingFaceH4/zephyr-7b-beta"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name)dataset = load_dataset("json", data_files="data.json", split = "train")# Tokenize the datasetdef preprocess_function(examples):inputs = [example['input'] for example in examples]targets = [examples['output'] for example in examples]model_inputs = tokenizer(inputs, padding=True, truncation=True)labels = tokenizer(targets, padding=True, truncation=True).input_idsmodel_inputs['labels'] = labelsreturn model_inputstokenized_datasets = dataset.map(preprocess_function, batched = True)training_args = TrainingArguments(output_dir = "./results",evaluation_strategy = "epoch",learning_rate = 2e-5,per_device_train_batch_size = 3,weight_decay = 0.01,)trainer = Trainer(model = model,args = training_args,train_dataset = tokenized_datasets["train"],eval_dataset = tokenized_datasets["validation"],)# Start fine-tuningtrainer.train()trainer.evaluate()model.save_pretrained("./fine_tuned_model")tokenizer.save_pretrained("./fine_tuned_model")client = InferenceClient("./fine_tuned_model")def respond(28 unmodified linesresponse += tokenyield responsedemo = gr.ChatInterface(respond,additional_inputs=[12 unmodified linesif __name__ == "__main__":demo.launch()1234567891028 unmodified lines3940414243444546474812 unmodified lines61626364import gradio as grfrom huggingface_hub import InferenceClient"""For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(28 unmodified linesresponse += tokenyield response"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond,additional_inputs=[12 unmodified linesif __name__ == "__main__":demo.launch()
app.py+9-46