Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,37 @@
|
|
| 1 |
-
from langchain import HuggingFaceHub
|
| 2 |
-
import os
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
|
| 5 |
-
load_dotenv() # take environment variables from .env.
|
| 6 |
-
|
| 7 |
-
import streamlit as st
|
| 8 |
-
|
| 9 |
-
## Function to load OpenAI model and get responses
|
| 10 |
-
def get_ai_response(context, question):
|
| 11 |
-
llm = HuggingFaceHub(
|
| 12 |
-
repo_id='EleutherAI/gpt-neo-2.7B',
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
'
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
response
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
st.
|
| 38 |
-
st.write(response)
|
|
|
|
| 1 |
+
from langchain import HuggingFaceHub
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
+
# load_dotenv() # take environment variables from .env.
|
| 6 |
+
|
| 7 |
+
import streamlit as st
|
| 8 |
+
|
| 9 |
+
## Function to load OpenAI model and get responses
|
| 10 |
+
def get_ai_response(context, question):
|
| 11 |
+
llm = HuggingFaceHub(
|
| 12 |
+
repo_id='EleutherAI/gpt-neo-2.7B',
|
| 13 |
+
model_kwargs={
|
| 14 |
+
'temperature': 0.6,
|
| 15 |
+
'max_length': 1000
|
| 16 |
+
}
|
| 17 |
+
)
|
| 18 |
+
# input_data = {"context": context, "question": question}
|
| 19 |
+
# response = llm(input_data)
|
| 20 |
+
prompt = f"Context: {context}\nQuestion: {question}\nAnswer:"
|
| 21 |
+
response = llm(prompt)
|
| 22 |
+
return response
|
| 23 |
+
|
| 24 |
+
## Initialize our Streamlit app
|
| 25 |
+
st.set_page_config(page_title="Q&A Demo")
|
| 26 |
+
|
| 27 |
+
st.header("Langchain Application")
|
| 28 |
+
|
| 29 |
+
context = st.text_area("Context: ", key="context")
|
| 30 |
+
question = st.text_input("Question: ", key="question")
|
| 31 |
+
submit = st.button("Ask the question")
|
| 32 |
+
|
| 33 |
+
## If ask button is clicked
|
| 34 |
+
if submit:
|
| 35 |
+
response = get_ai_response(context, question)
|
| 36 |
+
st.subheader("The Response is")
|
| 37 |
+
st.write(response)
|
|
|