Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,10 +13,11 @@ import os
|
|
13 |
|
14 |
print(os.listdir('.'))
|
15 |
|
|
|
16 |
# Download the 'punkt' package
|
17 |
nltk.download('punkt')
|
18 |
|
19 |
-
openai.api_key = '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'
|
20 |
|
21 |
# Define your model architecture
|
22 |
class Bert_model(nn.Module):
|
@@ -95,6 +96,33 @@ def explain_term(term):
|
|
95 |
|
96 |
# Streamlit code to upload file
|
97 |
st.title('FinQA (Financial Question-Answering)')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
99 |
|
100 |
# Select language
|
@@ -136,7 +164,7 @@ if uploaded_file is not None:
|
|
136 |
chat_history = "\n".join([sentence[0] for sentence in top_5_sentences])
|
137 |
|
138 |
# Ask the question using OpenAI API
|
139 |
-
openai.api_key = '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' # Replace with your actual OpenAI API key
|
140 |
|
141 |
response = openai.ChatCompletion.create(
|
142 |
model="gpt-4",
|
|
|
13 |
|
14 |
print(os.listdir('.'))
|
15 |
|
16 |
+
|
17 |
# Download the 'punkt' package
|
18 |
nltk.download('punkt')
|
19 |
|
20 |
+
#openai.api_key = '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'
|
21 |
|
22 |
# Define your model architecture
|
23 |
class Bert_model(nn.Module):
|
|
|
96 |
|
97 |
# Streamlit code to upload file
|
98 |
st.title('FinQA (Financial Question-Answering)')
|
99 |
+
|
100 |
+
api_key = st.text_input("Enter your OpenAI API key:", type="password")
|
101 |
+
|
102 |
+
if api_key:
|
103 |
+
try:
|
104 |
+
openai.api_key = api_key
|
105 |
+
|
106 |
+
# Test the API key by making a small request
|
107 |
+
openai.ChatCompletion.create(
|
108 |
+
model="gpt-4",
|
109 |
+
messages=[
|
110 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
111 |
+
{"role": "user", "content": "Hello"},
|
112 |
+
],
|
113 |
+
)
|
114 |
+
|
115 |
+
# If the above code doesn't raise an exception, the API key is valid
|
116 |
+
st.success("API key is valid!")
|
117 |
+
|
118 |
+
# Continue with the rest of your code...
|
119 |
+
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
120 |
+
|
121 |
+
except Exception as e:
|
122 |
+
st.error(f"Failed to validate API key: {e}")
|
123 |
+
else:
|
124 |
+
st.warning("Please enter your OpenAI API key.")
|
125 |
+
|
126 |
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
127 |
|
128 |
# Select language
|
|
|
164 |
chat_history = "\n".join([sentence[0] for sentence in top_5_sentences])
|
165 |
|
166 |
# Ask the question using OpenAI API
|
167 |
+
#openai.api_key = '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' # Replace with your actual OpenAI API key
|
168 |
|
169 |
response = openai.ChatCompletion.create(
|
170 |
model="gpt-4",
|