krisha06 commited on
Commit
a9279c3
·
verified ·
1 Parent(s): 83de309

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -3,6 +3,9 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
3
  from huggingface_hub import Repository
4
  import os
5
 
 
 
 
6
  # Define model directory and Hugging Face repo name
7
  model_dir = "./tuned_model" # Directory where the fine-tuned model is saved
8
  repo_name = "krisha06/Python_tutor" # Replace with your Hugging Face repo name
@@ -20,7 +23,7 @@ if upload_model_button:
20
  if os.path.exists(model_dir):
21
  # Initialize the Hugging Face Repository and push model to the Hub
22
  repo = Repository(local_dir=model_dir, clone_from=repo_name)
23
- repo.push_to_hub()
24
  st.success("Model uploaded to Hugging Face Hub successfully!")
25
  else:
26
  st.error("Model directory does not exist. Please make sure the model is fine-tuned first.")
@@ -30,7 +33,6 @@ st.header("Ask Me Any Coding Question!")
30
 
31
  # Load model and tokenizer (either from local directory or Hugging Face Hub)
32
  model_name = repo_name # Use the repo name if the model is on Hugging Face Hub, else use local dir
33
- token = "<HUGGINGFACE_TOKEN>" # Replace with your Hugging Face token if the model is private
34
 
35
  if os.path.exists(model_dir):
36
  # Load the model and tokenizer from the local directory
 
3
  from huggingface_hub import Repository
4
  import os
5
 
6
+ # Retrieve the Hugging Face token from Streamlit secrets
7
+ token = st.secrets["HUGGINGFACE_TOKEN"] # Ensure your secret key is "HUGGINGFACE_TOKEN"
8
+
9
  # Define model directory and Hugging Face repo name
10
  model_dir = "./tuned_model" # Directory where the fine-tuned model is saved
11
  repo_name = "krisha06/Python_tutor" # Replace with your Hugging Face repo name
 
23
  if os.path.exists(model_dir):
24
  # Initialize the Hugging Face Repository and push model to the Hub
25
  repo = Repository(local_dir=model_dir, clone_from=repo_name)
26
+ repo.push_to_hub(token=token) # Use the token from Streamlit secrets
27
  st.success("Model uploaded to Hugging Face Hub successfully!")
28
  else:
29
  st.error("Model directory does not exist. Please make sure the model is fine-tuned first.")
 
33
 
34
  # Load model and tokenizer (either from local directory or Hugging Face Hub)
35
  model_name = repo_name # Use the repo name if the model is on Hugging Face Hub, else use local dir
 
36
 
37
  if os.path.exists(model_dir):
38
  # Load the model and tokenizer from the local directory