Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +37 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Q&A Chatbot
|
| 2 |
+
from langchain.llms import OpenAI
|
| 3 |
+
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv() # take environment variables from .env.
|
| 7 |
+
|
| 8 |
+
import streamlit as st
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
## Function to load OpenAI model and get respones
|
| 13 |
+
|
| 14 |
+
def get_openai_response(question):
|
| 15 |
+
llm=OpenAI(model_name="text-davinci-003",temperature=0.5,openai_api_key=os.getenv("OPEN_API_KEY"))
|
| 16 |
+
response=llm(question)
|
| 17 |
+
return response
|
| 18 |
+
|
| 19 |
+
##initialize our streamlit app
|
| 20 |
+
|
| 21 |
+
st.set_page_config(page_title="Q&A Demo")
|
| 22 |
+
|
| 23 |
+
st.header("Langchain Application")
|
| 24 |
+
|
| 25 |
+
input=st.text_input("Input: ",key="input")
|
| 26 |
+
response=get_openai_response(input)
|
| 27 |
+
|
| 28 |
+
submit=st.button("Ask the question")
|
| 29 |
+
|
| 30 |
+
## If ask button is clicked
|
| 31 |
+
|
| 32 |
+
if submit:
|
| 33 |
+
st.subheader("The Response is")
|
| 34 |
+
st.write(response)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain == 0.0.332
|
| 2 |
+
OpenAI == 0.28.0
|
| 3 |
+
streamlit
|
| 4 |
+
python-dotenv==1.0.0
|
| 5 |
+
huggingface_hub
|