Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,14 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
3 |
import torch
|
4 |
import hashlib
|
5 |
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Set up logging
|
8 |
logging.basicConfig(filename="chatbot.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
@@ -91,7 +99,10 @@ III. Company General Info
|
|
91 |
system_prompt = f"{system_persona}\nHere is the knowledge base for your reference:\n{knowledge_base}\nAnswer the user's question based on the information above, following the constraints and communication style outlined in the persona."
|
92 |
|
93 |
# Load Gemma-2B model và tokenizer
|
94 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
|
|
95 |
tokenizer.pad_token = tokenizer.eos_token
|
96 |
|
97 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
3 |
import torch
|
4 |
import hashlib
|
5 |
import logging
|
6 |
+
from huggingface_hub import login
|
7 |
+
import os
|
8 |
+
|
9 |
+
# Lấy token từ secrets trong Hugging Face Spaces
|
10 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") # "HF_TOKEN" là tên biến bạn đặt trong Secrets
|
11 |
+
if not HF_TOKEN:
|
12 |
+
raise ValueError("HF_TOKEN not found in environment variables. Please set it in Hugging Face Spaces Secrets.")
|
13 |
+
login(token=HF_TOKEN)
|
14 |
|
15 |
# Set up logging
|
16 |
logging.basicConfig(filename="chatbot.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
|
|
99 |
system_prompt = f"{system_persona}\nHere is the knowledge base for your reference:\n{knowledge_base}\nAnswer the user's question based on the information above, following the constraints and communication style outlined in the persona."
|
100 |
|
101 |
# Load Gemma-2B model và tokenizer
|
102 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
103 |
+
"google/gemma-2b",
|
104 |
+
padding_side="left"
|
105 |
+
)
|
106 |
tokenizer.pad_token = tokenizer.eos_token
|
107 |
|
108 |
model = AutoModelForCausalLM.from_pretrained(
|