krisha06 commited on
Commit
d606bf0
·
verified ·
1 Parent(s): a54c990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -3,12 +3,12 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
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
12
 
13
  # Streamlit App Title
14
  st.title("AI Coding Mentor")
@@ -23,7 +23,7 @@ if upload_model_button:
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.")
@@ -35,7 +35,7 @@ st.header("Ask Me Any Coding Question!")
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
39
  model = AutoModelForCausalLM.from_pretrained(model_dir, use_auth_token=token)
40
  tokenizer = AutoTokenizer.from_pretrained(model_dir, use_auth_token=token)
41
  else:
 
3
  from huggingface_hub import Repository
4
  import os
5
 
6
+ # Retrieve Hugging Face token from Streamlit secrets
7
+ token = st.secrets["HUGGINGFACE_TOKEN"] # Make sure to add your Hugging Face token to Streamlit secrets
8
 
9
  # Define model directory and Hugging Face repo name
10
+ model_dir = "./tuned_model" # The directory where the fine-tuned model is saved
11
+ repo_name = "user06/Python_tutor" # Replace with your Hugging Face repo name
12
 
13
  # Streamlit App Title
14
  st.title("AI Coding Mentor")
 
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 for authentication
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.")
 
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 local directory
39
  model = AutoModelForCausalLM.from_pretrained(model_dir, use_auth_token=token)
40
  tokenizer = AutoTokenizer.from_pretrained(model_dir, use_auth_token=token)
41
  else: