Upload 3 files
Browse files- .env +2 -0
- app.py +24 -16
- requirements.txt +5 -3
.env
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# OPENAI_API_KEY=""
|
2 |
+
HUGGINGFACEHUB_API_TOKEN=""
|
app.py
CHANGED
@@ -1,31 +1,39 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
from langchain.llms import HuggingFace
|
5 |
-
|
6 |
-
## Function to return the response
|
7 |
def load_answer(question):
|
8 |
-
#
|
9 |
-
llm =
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
return answer
|
12 |
|
13 |
-
|
14 |
-
st.set_page_config(page_title="LangChain Demo", page_icon="
|
15 |
-
st.header("
|
16 |
|
17 |
-
|
18 |
def get_text():
|
19 |
input_text = st.text_input("You: ", key="input")
|
20 |
return input_text
|
21 |
|
22 |
user_input = get_text()
|
23 |
-
response = load_answer(user_input)
|
24 |
|
25 |
-
submit = st.button(
|
26 |
|
27 |
-
|
28 |
-
if submit:
|
|
|
29 |
st.subheader("Answer:")
|
30 |
-
|
31 |
st.write(response)
|
|
|
1 |
import streamlit as st
|
2 |
+
from langchain.llms import HuggingFaceHub
|
3 |
+
from langchain import PromptTemplate, LLMChain
|
4 |
|
5 |
+
## Function to return the response using the HuggingFace Model
|
|
|
|
|
|
|
6 |
def load_answer(question):
|
7 |
+
# Initialize the HuggingFaceHub LLM
|
8 |
+
llm = HuggingFaceHub(
|
9 |
+
repo_id="google/flan-t5-large",
|
10 |
+
# huggingfacehub_api_token="",
|
11 |
+
model_kwargs={"temperature": 0}
|
12 |
+
)
|
13 |
+
|
14 |
+
# Create a prompt template for the question
|
15 |
+
template = PromptTemplate(input_variables=["question"], template="{question}")
|
16 |
+
llm_chain = LLMChain(prompt=template, llm=llm)
|
17 |
+
|
18 |
+
# Generate the answer using the LLM chain
|
19 |
+
answer = llm_chain.run(question)
|
20 |
return answer
|
21 |
|
22 |
+
# App UI starts here
|
23 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
24 |
+
st.header("LangChain Demo")
|
25 |
|
26 |
+
# Gets the user input
|
27 |
def get_text():
|
28 |
input_text = st.text_input("You: ", key="input")
|
29 |
return input_text
|
30 |
|
31 |
user_input = get_text()
|
|
|
32 |
|
33 |
+
submit = st.button('Generate')
|
34 |
|
35 |
+
# If generate button is clicked
|
36 |
+
if submit and user_input:
|
37 |
+
response = load_answer(user_input)
|
38 |
st.subheader("Answer:")
|
|
|
39 |
st.write(response)
|
requirements.txt
CHANGED
@@ -1,3 +1,5 @@
|
|
1 |
-
langchain
|
2 |
-
|
3 |
-
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
langchain-community
|
3 |
+
# Openai
|
4 |
+
streamlit
|
5 |
+
huggingface_hub
|