Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
-
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
-
import os
|
| 7 |
# Function to load model and tokenizer only once
|
| 8 |
@st.cache_resource # This decorator caches the loading process
|
| 9 |
def load_resources():
|
| 10 |
-
load_dotenv()
|
| 11 |
# Load the pre-trained Llama3 model (or your fine-tuned model)
|
| 12 |
-
huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
|
| 13 |
-
|
| 14 |
-
# Run the huggingface-cli login command from the Python script using subprocess
|
| 15 |
-
subprocess.run(["huggingface-cli", "login", "--token", huggingface_token])
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B")
|
| 17 |
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B")
|
| 18 |
print("Model and tokenizer loaded.")
|
|
@@ -34,6 +27,10 @@ user_query = st.text_input("Your Query:", "")
|
|
| 34 |
|
| 35 |
if user_query:
|
| 36 |
with st.spinner("Generating response..."):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Tokenize the input query
|
| 38 |
inputs = tokenizer(user_query, return_tensors="pt")
|
| 39 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
+
|
|
|
|
|
|
|
| 5 |
# Function to load model and tokenizer only once
|
| 6 |
@st.cache_resource # This decorator caches the loading process
|
| 7 |
def load_resources():
|
|
|
|
| 8 |
# Load the pre-trained Llama3 model (or your fine-tuned model)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B")
|
| 10 |
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B")
|
| 11 |
print("Model and tokenizer loaded.")
|
|
|
|
| 27 |
|
| 28 |
if user_query:
|
| 29 |
with st.spinner("Generating response..."):
|
| 30 |
+
# Retrieve the tokenizer from session state
|
| 31 |
+
tokenizer = st.session_state.tokenizer
|
| 32 |
+
model = st.session_state.model
|
| 33 |
+
|
| 34 |
# Tokenize the input query
|
| 35 |
inputs = tokenizer(user_query, return_tensors="pt")
|
| 36 |
|