taimoor61 commited on
Commit
bbacfe7
·
1 Parent(s): 5fc3c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -5,15 +5,17 @@ from dotenv import load_dotenv
5
  import streamlit as st
6
  from langchain.llms import openai
7
 
8
- # Load environment variables
9
- load_dotenv()
10
 
11
  # Function to get OpenAI response
12
  def get_openai_response(question):
13
  try:
14
- api_key = os.environ["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"]
 
 
15
  llm = openai.OpenAI(
16
- model_name="text-davinci-003", temperature=0.5, openai_api_key=api_key
17
  )
18
  with st.spinner("Generating response..."):
19
  response = llm(question)
@@ -22,6 +24,9 @@ def get_openai_response(question):
22
  st.error(f"Error: {e}")
23
  return None
24
 
 
 
 
25
  # Initialize Streamlit app
26
  st.set_page_config(page_title="Enhanced Q&A Demo")
27
  st.header("Langchain App")
 
5
  import streamlit as st
6
  from langchain.llms import openai
7
 
8
+ # Load environment variables (if using a .env file)
9
+ # load_dotenv() # Uncomment this line if using a .env file
10
 
11
  # Function to get OpenAI response
12
  def get_openai_response(question):
13
  try:
14
+ # Access API key securely (choose one of the methods below)
15
+ # api_key = os.environ["OPENAI_API_KEY"] # Method 1: Using environment variables
16
+ # api_key = "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" # Method 2: Direct inclusion (not recommended)
17
  llm = openai.OpenAI(
18
+ model_name="text-davinci-003", temperature=0.5, openai_api_key=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
19
  )
20
  with st.spinner("Generating response..."):
21
  response = llm(question)
 
24
  st.error(f"Error: {e}")
25
  return None
26
 
27
+ # Rest of the code remains the same...
28
+
29
+
30
  # Initialize Streamlit app
31
  st.set_page_config(page_title="Enhanced Q&A Demo")
32
  st.header("Langchain App")