Views
No views yet
1
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "kr-manish/Mistral-7B-autotrain-text-python-vf1"
5tokenizer = AutoTokenizer.from_pretrained(model_path)
6model = AutoModelForCausalLM.from_pretrained(model_path)
7
8#input_text = "Maximum Prefix Sum possible by merging two given arrays | Python3 implementation of the above approach ; Stores the maximum prefix sum of the array A [ ] ; Traverse the array A [ ] ; Stores the maximum prefix sum of the array B [ ] ; Traverse the array B [ ] ;"
9input_text ="Program to convert Centimeters to Pixels | Function to convert centimeters to pixels ; Driver Code"
10# Tokenize input text
11input_ids = tokenizer.encode(input_text, return_tensors="pt")
12
13# Generate output text
14output = model.generate(input_ids, max_length=1024, num_return_sequences=1, do_sample=True)
15
16# Decode and print output
17generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
18print(generated_text)
19
20#Program to convert Centimeters to Pixels | Function to convert centimeters to pixels ; Driver Code [/INST] def cmToPixels ( cm ) : NEW_LINE INDENT return ( ( cm * 100 ) / 17 ) NEW_LINE DEDENT cm = 105.25 NEW_LINE print ( round ( cmToPixels ( cm ) , 3 ) ) NEW_LINE