ashaduzzaman commited on
Commit
1106f9e
·
verified ·
1 Parent(s): 70cfb2f

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +2 -0
  2. app.py +24 -16
  3. 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
- # from langchain.llms import OpenAI
4
- from langchain.llms import HuggingFace
5
-
6
- ## Function to return the response
7
  def load_answer(question):
8
- # llm = OpenAI(model_name="gpt-3.5-turbo")
9
- llm = HuggingFace(model_name="google/flan-t5-large")
10
- answer = llm(question)
 
 
 
 
 
 
 
 
 
 
11
  return answer
12
 
13
- ## App UI starts here
14
- st.set_page_config(page_title="LangChain Demo", page_icon="🦜")
15
- st.header("🦜️🔗 LangChain Demo")
16
 
17
- ## Gets the user input
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("Generate")
26
 
27
- ## If generate button is clicked
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
- Openai
3
- Streamlit
 
 
 
1
+ langchain
2
+ langchain-community
3
+ # Openai
4
+ streamlit
5
+ huggingface_hub