addcorpbc commited on
Commit ·
a5aa51c
1
Parent(s): 4117a2c
Fix syntax issue with Gradio share
Browse files123456789101112131415161718192021222324252627282930316 unmodified lines3839404142434445464748from transformers import AutoTokenizer, AutoModelForCausalLMimport gradio as grimport os# 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 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)cache_dir=cache_dir,use_auth_token=hf_token # Pass the token for authenticated model loading)def recommend(user_input):"""Generate career recommendations based on user input using LLaMA."""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!")# Launch the Gradio appinterface.launch(`share=True`)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869706 unmodified lines7778798081828384858687from 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'.")# Set up caching directorycache_dir = "./model_cache"os.makedirs(cache_dir, exist_ok=True)# 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 performancecache_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 directorynum_train_epochs=3, # number of training epochsper_device_train_batch_size=8, # batch size for trainingper_device_eval_batch_size=8, # batch size for evaluationwarmup_steps=500, # number of warmup steps for learning rate schedulerweight_decay=0.01, # strength of weight decaylogging_dir='./logs', # directory for storing logslogging_steps=10,save_steps=500,evaluation_strategy="epoch", # evaluate after each epoch)trainer = Trainer(model=model, # the pre-trained modelargs=training_args, # training argumentstrain_dataset=dataset["train"], # training dataseteval_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 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", lines=2),outputs=gr.Textbox(label="Career Recommendations", lines=4),title="AI-Powered Magic City Career Counselor", # Updated titledescription="Provide a description of your career goals, and get personalized career suggestions!" # Description update)# Launch the Gradio app and share itinterface.launch(share=True) # Corrected syntax: share=True, no backticks
app.py+51-12