Spaces:
Build error
Build error
Updated model id and added access check
Browse files
app.py
CHANGED
|
@@ -2,12 +2,28 @@ import streamlit as st
|
|
| 2 |
import os
|
| 3 |
from torch import cuda, bfloat16
|
| 4 |
import transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Retrieve the Hugging Face authentication token from the environment variables
|
| 7 |
hf_auth = os.getenv('HF_AUTH_TOKEN')
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
model_id = 'meta-llama/Llama-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
|
| 12 |
|
| 13 |
# Set quantization configuration to load large model with less GPU memory
|
|
@@ -39,7 +55,7 @@ model.eval()
|
|
| 39 |
# Load tokenizer
|
| 40 |
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id, use_auth_token=hf_auth)
|
| 41 |
|
| 42 |
-
st.title("Chatbot using Meta-Llama-
|
| 43 |
|
| 44 |
prompt = st.text_area("Enter your prompt:")
|
| 45 |
|
|
|
|
| 2 |
import os
|
| 3 |
from torch import cuda, bfloat16
|
| 4 |
import transformers
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
# Function to check access to the model
|
| 8 |
+
def check_access(model_id, token):
|
| 9 |
+
url = f"https://huggingface.co/{model_id}/resolve/main/config.json"
|
| 10 |
+
headers = {"Authorization": f"Bearer {token}"}
|
| 11 |
+
response = requests.head(url, headers=headers)
|
| 12 |
+
if response.status_code == 200:
|
| 13 |
+
print(f"Access to {model_id} is confirmed.")
|
| 14 |
+
else:
|
| 15 |
+
st.error(f"Cannot access {model_id}: {response.status_code} - {response.reason}")
|
| 16 |
+
st.stop()
|
| 17 |
|
| 18 |
# Retrieve the Hugging Face authentication token from the environment variables
|
| 19 |
hf_auth = os.getenv('HF_AUTH_TOKEN')
|
| 20 |
|
| 21 |
+
# Model ID
|
| 22 |
+
model_id = 'meta-llama/Meta-Llama-3-8B-Instruct'
|
| 23 |
+
|
| 24 |
+
# Check access to the model
|
| 25 |
+
check_access(model_id, hf_auth)
|
| 26 |
+
|
| 27 |
device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
|
| 28 |
|
| 29 |
# Set quantization configuration to load large model with less GPU memory
|
|
|
|
| 55 |
# Load tokenizer
|
| 56 |
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id, use_auth_token=hf_auth)
|
| 57 |
|
| 58 |
+
st.title("Chatbot using Meta-Llama-3-8B-Instruct")
|
| 59 |
|
| 60 |
prompt = st.text_area("Enter your prompt:")
|
| 61 |
|