Spaces:
Runtime error
Runtime error
arithescientist
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -12,14 +12,26 @@ from langchain.llms import HuggingFacePipeline
|
|
12 |
|
13 |
# Initialize conversation history
|
14 |
if 'history' not in st.session_state:
|
15 |
-
st.session_state
|
16 |
|
17 |
# Set up the Llama-2-7b-chat-hf model
|
18 |
model_id = "meta-llama/Llama-2-7b-chat-hf"
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Create the text-generation pipeline with appropriate parameters
|
25 |
pipe = pipeline(
|
@@ -37,6 +49,9 @@ pipe = pipeline(
|
|
37 |
# Wrap the pipeline with HuggingFacePipeline for use in LangChain
|
38 |
llm = HuggingFacePipeline(pipeline=pipe)
|
39 |
|
|
|
|
|
|
|
40 |
# Step 1: Upload CSV data file (or use default)
|
41 |
st.title("Natural Language to SQL Query App with Enhanced Insights")
|
42 |
st.write("Upload a CSV file to get started, or use the default dataset.")
|
|
|
12 |
|
13 |
# Initialize conversation history
|
14 |
if 'history' not in st.session_state:
|
15 |
+
st.session_state['history'] = []
|
16 |
|
17 |
# Set up the Llama-2-7b-chat-hf model
|
18 |
model_id = "meta-llama/Llama-2-7b-chat-hf"
|
19 |
|
20 |
+
# Get your Hugging Face token (it's stored as a secret in your Space)
|
21 |
+
hf_token = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
22 |
+
|
23 |
+
if hf_token is None:
|
24 |
+
st.error("Hugging Face API token is not set. Please set the HUGGINGFACEHUB_API_TOKEN secret in your Space.")
|
25 |
+
st.stop()
|
26 |
+
|
27 |
+
# Load the tokenizer and model with the token
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=hf_token)
|
29 |
+
model = AutoModelForCausalLM.from_pretrained(
|
30 |
+
model_id,
|
31 |
+
use_auth_token=hf_token,
|
32 |
+
device_map='auto',
|
33 |
+
torch_dtype='auto' # Adjust based on your environment
|
34 |
+
)
|
35 |
|
36 |
# Create the text-generation pipeline with appropriate parameters
|
37 |
pipe = pipeline(
|
|
|
49 |
# Wrap the pipeline with HuggingFacePipeline for use in LangChain
|
50 |
llm = HuggingFacePipeline(pipeline=pipe)
|
51 |
|
52 |
+
# ... rest of your code ...
|
53 |
+
|
54 |
+
|
55 |
# Step 1: Upload CSV data file (or use default)
|
56 |
st.title("Natural Language to SQL Query App with Enhanced Insights")
|
57 |
st.write("Upload a CSV file to get started, or use the default dataset.")
|