Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
|
11 |
from dotenv import load_dotenv
|
12 |
from htmlTemplates import css
|
13 |
|
|
|
|
|
|
|
14 |
# Load environment variables
|
15 |
load_dotenv()
|
16 |
|
@@ -23,7 +26,7 @@ def load_pipeline():
|
|
23 |
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left", trust_remote_code=True)
|
24 |
model = AutoModelForCausalLM.from_pretrained(
|
25 |
model_name,
|
26 |
-
torch_dtype=torch.
|
27 |
device_map="auto", # Automatically map model to available devices (e.g., GPU if available)
|
28 |
trust_remote_code=True
|
29 |
)
|
@@ -33,7 +36,7 @@ def load_pipeline():
|
|
33 |
task="text-generation",
|
34 |
model=model,
|
35 |
tokenizer=tokenizer,
|
36 |
-
torch_dtype=torch.
|
37 |
device_map="auto",
|
38 |
return_full_text=True # Required for LangChain compatibility
|
39 |
)
|
@@ -100,7 +103,6 @@ def handle_question(question, vectorstore=None):
|
|
100 |
return llm_chain.run(instruction=question)
|
101 |
|
102 |
def main():
|
103 |
-
st.set_page_config(page_title="Chat with Notes and AI", page_icon=":books:", layout="wide")
|
104 |
st.write(css, unsafe_allow_html=True)
|
105 |
|
106 |
# Initialize session state
|
|
|
11 |
from dotenv import load_dotenv
|
12 |
from htmlTemplates import css
|
13 |
|
14 |
+
# Set Streamlit page configuration
|
15 |
+
st.set_page_config(page_title="Chat with Notes and AI", page_icon=":books:", layout="wide")
|
16 |
+
|
17 |
# Load environment variables
|
18 |
load_dotenv()
|
19 |
|
|
|
26 |
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left", trust_remote_code=True)
|
27 |
model = AutoModelForCausalLM.from_pretrained(
|
28 |
model_name,
|
29 |
+
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32, # Use float16 for GPU, float32 for CPU
|
30 |
device_map="auto", # Automatically map model to available devices (e.g., GPU if available)
|
31 |
trust_remote_code=True
|
32 |
)
|
|
|
36 |
task="text-generation",
|
37 |
model=model,
|
38 |
tokenizer=tokenizer,
|
39 |
+
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
|
40 |
device_map="auto",
|
41 |
return_full_text=True # Required for LangChain compatibility
|
42 |
)
|
|
|
103 |
return llm_chain.run(instruction=question)
|
104 |
|
105 |
def main():
|
|
|
106 |
st.write(css, unsafe_allow_html=True)
|
107 |
|
108 |
# Initialize session state
|