Spaces:
Sleeping
Sleeping
ashishomi89
commited on
Uploading app and requirements file
Browse files- app.py +30 -0
- requirements.txt +9 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#Q&A chatbot
|
2 |
+
from langchain.llms import OpenAI
|
3 |
+
from constants import OPENAI_API_KEY
|
4 |
+
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
7 |
+
load_dotenv() #take environment variables from .env
|
8 |
+
|
9 |
+
import streamlit as st
|
10 |
+
import os
|
11 |
+
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
12 |
+
|
13 |
+
|
14 |
+
#Function to load OpenAI model and get response
|
15 |
+
def get_openai_response(question):
|
16 |
+
llm=OpenAI(openai_api_key=os.getenv('OPENAI_API_KEY'),model_name='gpt-3.5-turbo-instruct',temperature=0.5)
|
17 |
+
response = llm(question)
|
18 |
+
return response
|
19 |
+
|
20 |
+
##initializing the streamlit app
|
21 |
+
st.set_page_config(page_title="Q&A Chatbot", page_icon="🤖", layout="centered", initial_sidebar_state="expanded")
|
22 |
+
st.header("LangChain Application")
|
23 |
+
input_question = st.text_input("Enter your question: ",key="input_question")
|
24 |
+
response = get_openai_response(input_question)
|
25 |
+
submit =st.button("Ask Question")
|
26 |
+
|
27 |
+
## if ask question button is clicked
|
28 |
+
if submit:
|
29 |
+
st.subheader("The Response Is: ")
|
30 |
+
st.write(response)
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
langchain
|
3 |
+
streamlit
|
4 |
+
ipykernel==6.29.3
|
5 |
+
PyPDF2
|
6 |
+
faiss-cpu
|
7 |
+
tiktoken
|
8 |
+
huggingface_hub
|
9 |
+
python-dotenv
|