Update app.py
Browse files123453 unmodified lines910111213141516171819202122232425262728293031327 unmodified lines40414243444546import gradio as grfrom unsloth import FastLanguageModelimport torch# Configuration3 unmodified linespeft_model_name = "limitedonly41/website_mistral7b_v02_1200_finetuned_5_big"# Load the model and tokenizermodel, tokenizer = FastLanguageModel.from_pretrained(model_name=peft_model_name, # YOUR MODEL YOU USED FOR TRAININGmax_seq_length=max_seq_length,dtype=dtype,load_in_4bit=load_in_4bit,)FastLanguageModel.for_inference(model) # Enable native 2x faster inferencedef return_prediction(prompt):inputs = tokenizer(prompt, return_tensors="pt").to("cuda")outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True)ans = tokenizer.batch_decode(outputs)[0]ans_pred = ans.split('### Response:')[1].split('<')[0]return ans_pred@spaces.GPUdef classify_website(site_text):prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.### Instruction:7 unmodified lines{site_text}### Response:"""return return_prediction(prompt)# Create a Gradio interfaceiface = gr.Interface(12343 unmodified lines89101112131415161718192021222324252627282930313233343536373839404142434445467 unmodified lines5455565758596061626364656667import gradio as grimport torch# Configuration3 unmodified linespeft_model_name = "limitedonly41/website_mistral7b_v02_1200_finetuned_5_big"# from unsloth import FastLanguageModel# # Load the model and tokenizer# model, tokenizer = FastLanguageModel.from_pretrained(# model_name=peft_model_name, # YOUR MODEL YOU USED FOR TRAINING# max_seq_length=max_seq_length,# dtype=dtype,# load_in_4bit=load_in_4bit,# )# FastLanguageModel.for_inference(model) # Enable native 2x faster inference# def return_prediction(prompt):# inputs = tokenizer(prompt, return_tensors="pt").to("cuda")# outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True)# ans = tokenizer.batch_decode(outputs)[0]# ans_pred = ans.split('### Response:')[1].split('<')[0]# return ans_pred@spaces.GPU()def classify_website(site_text):from unsloth import FastLanguageModel# Load the model and tokenizermodel, tokenizer = FastLanguageModel.from_pretrained(model_name=peft_model_name, # YOUR MODEL YOU USED FOR TRAININGmax_seq_length=max_seq_length,dtype=dtype,load_in_4bit=load_in_4bit,)FastLanguageModel.for_inference(model) # Enable native 2x faster inferenceprompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.### Instruction:7 unmodified lines{site_text}### Response:"""inputs = tokenizer(prompt, return_tensors="pt").to("cuda")outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True)ans = tokenizer.batch_decode(outputs)[0]ans_pred = ans.split('### Response:')[1].split('<')[0]return ans_pred# return return_prediction(prompt)# Create a Gradio interfaceiface = gr.Interface(
app.py+38-17