Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,12 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 3 |
from huggingface_hub import Repository
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Retrieve
|
| 7 |
-
token = st.secrets["HUGGINGFACE_TOKEN"] #
|
| 8 |
|
| 9 |
# Define model directory and Hugging Face repo name
|
| 10 |
-
model_dir = "./tuned_model" #
|
| 11 |
-
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
|
| 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
|
| 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:
|