addcorpbc commited on
Commit ·
a5aa51c
1
Parent(s): 4117a2c
Fix syntax issue with Gradio share
Browse files11234567891010111211121314171516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656628676869706 unmodified lines7778794142434480818283848547488687from transformers import AutoTokenizer, AutoModelForCausalLMfrom transformers import AutoTokenizer, AutoModelForCausalLM, Trainer, TrainingArgumentsimport gradio as grimport osfrom datasets import load_dataset
# Authenticate using a token from environment variableshf_token = os.getenv("HFTOKEN") # Updated to match your environment variable nameif not hf_token: raise ValueError("Hugging Face token is missing. Please add it as an environment variable named 'HFTOKEN'.")
# Print the token for debuggingprint("Hugging Face Token:", hf_token)
# Set up caching directorycache_dir = "./model_cache"os.makedirs(cache_dir, exist_ok=True)
# Load LLaMA model and tokenizer# Load pre-trained model and tokenizertokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf", cache_dir=cache_dir, use_auth_token=hf_token)model = AutoModelForCausalLM.from_pretrained( "meta-llama/Llama-2-7b-hf", device_map="auto", # Automatically map layers to available hardware (CPU here) load_in_8bit=True, # Enable quantization for better performance cache_dir=cache_dir, use_auth_token=hf_token # Pass the token for authenticated model loading)
# Fine-tuning data file pathstrain_file_paths = [ "C:/Users/addco/Desktop/Magic CIty Training/Quizes/quizes json files/Card Sorting", "C:/Users/addco/Desktop/Magic CIty Training/Quizes/quizes json files/MBPTI", "C:/Users/addco/Desktop/Magic CIty Training/Quizes/quizes json files/Riasec", "C:/Users/addco/Desktop/Magic CIty Training/Quizes/quizes json files/Strong Interest Index", "C:/Users/addco/Desktop/Magic CIty Training/Quizes/quizes json files/Counselor Personality"]
# Load your dataset for fine-tuningdataset = load_dataset( "json", data_files={file_path: file_path for file_path in train_file_paths})
# Fine-tuning configurationstraining_args = TrainingArguments( output_dir='./results', # output directory num_train_epochs=3, # number of training epochs per_device_train_batch_size=8, # batch size for training per_device_eval_batch_size=8, # batch size for evaluation warmup_steps=500, # number of warmup steps for learning rate scheduler weight_decay=0.01, # strength of weight decay logging_dir='./logs', # directory for storing logs logging_steps=10, save_steps=500, evaluation_strategy="epoch", # evaluate after each epoch)
trainer = Trainer( model=model, # the pre-trained model args=training_args, # training arguments train_dataset=dataset["train"], # training dataset eval_dataset=dataset["validation"], # evaluation dataset)
# Fine-tune the modeltrainer.train()
# Define the recommendation function (to use after fine-tuning)def recommend(user_input): """ Generate career recommendations based on user input using LLaMA. Generate career recommendations based on user input using the fine-tuned LLaMA model. """ prompt = f""" User input: {user_input}6 unmodified lines# Define the Gradio interfaceinterface = gr.Interface( fn=recommend, inputs=gr.Textbox(label="Describe your career interests and goals"), outputs="text", title="AI-Powered Career Recommendation Tool (LLaMA)", description="Provide a description of your career goals, and get personalized career suggestions!" inputs=gr.Textbox(label="Describe your career interests and goals", lines=2), outputs=gr.Textbox(label="Career Recommendations", lines=4), title="AI-Powered Magic City Career Counselor", # Updated title description="Provide a description of your career goals, and get personalized career suggestions!" # Description update)
# Launch the Gradio appinterface.launch(`share=True`)# Launch the Gradio app and share itinterface.launch(share=True) # Corrected syntax: share=True, no backticksapp.py+51-12