ujaganna commited on
Commit
6812716
·
verified ·
1 Parent(s): c20d5e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -12
app.py CHANGED
@@ -1,24 +1,49 @@
1
- import openai
2
- from langchain.chains import RetrievalQA
3
- from langchain.chat_models import ChatOpenAI
4
- from langchain.document_loaders import CSVLoader
5
- from langchain.vectorstores import DocArrayInMemorySearch
6
- from IPython.display import display, Markdown
7
  from langchain.llms import OpenAI
8
- from langchain_community.document_loaders import Docx2txtLoader
9
- from langchain_community.document_loaders import UnstructuredWordDocumentLoader
10
- from langchain.indexes import VectorstoreIndexCreator
11
- from langchain_community.document_loaders import PyPDFLoader
12
-
13
  import os
14
 
15
  from dotenv import load_dotenv, find_dotenv
16
  _ = load_dotenv(find_dotenv()) # read local .env file
17
 
18
- os.getenv("OPENAI_API_KEY"))
 
 
 
 
 
 
 
19
 
20
  loader = PyPDFLoader("Firm_Data.pdf")
21
  index = VectorstoreIndexCreator(
22
  vectorstore_cls=DocArrayInMemorySearch
23
  ).from_loaders([loader])
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
 
 
 
 
 
2
  from langchain.llms import OpenAI
 
 
 
 
 
3
  import os
4
 
5
  from dotenv import load_dotenv, find_dotenv
6
  _ = load_dotenv(find_dotenv()) # read local .env file
7
 
8
+
9
+ import streamlit as st
10
+ import os
11
+
12
+
13
+ os.getenv("OPENAI_API_KEY")
14
+
15
+ ## Function to load OpenAI model and get respones
16
 
17
  loader = PyPDFLoader("Firm_Data.pdf")
18
  index = VectorstoreIndexCreator(
19
  vectorstore_cls=DocArrayInMemorySearch
20
  ).from_loaders([loader])
21
 
22
+
23
+ def get_openai_response(index, question):
24
+ llm_replacement_model = OpenAI(temperature=0,
25
+ model='gpt-3.5-turbo-instruct')
26
+ response = index.query(question,
27
+ llm = llm_replacement_model)
28
+ return response
29
+
30
+ st.set_page_config(page_title="Ask Questions on S&P 500 companies financials")
31
+
32
+ st.header("Langchain Application")
33
+
34
+ input=st.text_input("Input: ",key="input")
35
+ response=get_openai_response(input)
36
+
37
+ submit=st.button("Ask the question")
38
+
39
+ ## If ask button is clicked
40
+
41
+ if submit:
42
+ st.subheader("The Response is")
43
+ st.write(response)
44
+
45
+
46
+
47
+
48
+
49
+