Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
# Q&A Chatbot
|
3 |
+
|
4 |
+
# imports
|
5 |
+
from langchain.llms import OpenAI
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
load_dotenv() # load the environment variables from .env
|
8 |
+
import streamlit as st
|
9 |
+
import os
|
10 |
+
|
11 |
+
################################## Function to load OpenAI model and get responses
|
12 |
+
def get_openai_response(question):
|
13 |
+
|
14 |
+
# create llm model
|
15 |
+
llm = OpenAI(openai_api_key=os.getenv("OPEN_API_KEY"),
|
16 |
+
model_name="gpt-3.5-turbo-instruct", # old deprecated: "text-davinci-003",
|
17 |
+
temperature=0.5,)
|
18 |
+
|
19 |
+
# get response using the inputted question
|
20 |
+
response = llm(question)
|
21 |
+
|
22 |
+
return response
|
23 |
+
|
24 |
+
################################## Initialize streamlit app
|
25 |
+
st.set_page_config(page_title="Q&A Demo")
|
26 |
+
st.header("Langchain Application")
|
27 |
+
|
28 |
+
# create a variable for the input
|
29 |
+
input = st.text_input("Ask a question: ", key="input")
|
30 |
+
|
31 |
+
# call OpenAI to get the response
|
32 |
+
response = get_openai_response(input)
|
33 |
+
|
34 |
+
# create a submit button
|
35 |
+
submit = st.button("Submit")
|
36 |
+
|
37 |
+
# if the button is clicked, submit will be true
|
38 |
+
if submit:
|
39 |
+
#st.subheader("The response is:")
|
40 |
+
st.write(response) # out the response
|