NoaiGPT commited on
Commit
64c34c3
1 Parent(s): 70297ae
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -3,7 +3,7 @@ import json
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer
5
  from peft import PeftModel
6
- from huggingface_hub import HfApi
7
  import gradio as gr
8
  import time
9
 
@@ -23,8 +23,9 @@ def load_model_and_tokenizer():
23
  merged_model = AutoModelForCausalLM.from_pretrained(local_model_path)
24
  else:
25
  print("Downloading model from Hugging Face Hub...")
26
- tokenizer = AutoTokenizer.from_pretrained(model_name)
27
- merged_model = AutoModelForCausalLM.from_pretrained(model_name)
 
28
 
29
  def merge_models():
30
  print("Loading base model...")
@@ -56,10 +57,12 @@ def push_to_hub(repo_name):
56
  except Exception as e:
57
  print(f"Repository already exists or error occurred: {e}")
58
 
 
59
  api.upload_folder(
60
  folder_path="merged_model",
61
  repo_id=repo_name,
62
  repo_type="model",
 
63
  )
64
  print("Model pushed successfully!")
65
 
 
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer
5
  from peft import PeftModel
6
+ from huggingface_hub import HfApi, HfFolder
7
  import gradio as gr
8
  import time
9
 
 
23
  merged_model = AutoModelForCausalLM.from_pretrained(local_model_path)
24
  else:
25
  print("Downloading model from Hugging Face Hub...")
26
+ token = os.getenv("HF_AUTH_TOKEN") # Ensure you set this environment variable with your Hugging Face token
27
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=token)
28
+ merged_model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=token)
29
 
30
  def merge_models():
31
  print("Loading base model...")
 
57
  except Exception as e:
58
  print(f"Repository already exists or error occurred: {e}")
59
 
60
+ token = os.getenv("HF_AUTH_TOKEN") # Ensure you set this environment variable with your Hugging Face token
61
  api.upload_folder(
62
  folder_path="merged_model",
63
  repo_id=repo_name,
64
  repo_type="model",
65
+ token=token
66
  )
67
  print("Model pushed successfully!")
68