gautamraj8044 commited on
Commit
6f5d887
1 Parent(s): d7739b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -34
app.py CHANGED
@@ -1,58 +1,95 @@
1
- import streamlit as st
2
- import langchain
3
- from langchain.llms import HuggingFaceHub
4
 
5
- #Function to return the response
6
- def load_answer(question):
7
- llm = HuggingFaceHub(repo_id="google/flan-t5-large")
8
- answer=llm(question)
9
- return answer
10
 
11
 
12
- #App UI starts here
13
- st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
14
- st.header("LangChain Demo")
15
 
16
- #Gets the user input
17
- def get_text():
18
- input_text = st.text_input("You: ", key="input")
19
- return input_text
20
 
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
 
30
- st.subheader("Answer:")
 
 
31
 
32
- st.write(response)
 
 
 
33
 
34
 
 
 
35
 
36
- #App UI starts here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
38
  st.header("LangChain Demo")
39
 
40
- #Gets the user input
41
  def get_text():
42
  input_text = st.text_input("You: ", key="input")
43
  return input_text
44
 
 
 
45
 
46
- user_input=get_text()
47
- response = load_answer(user_input)
48
-
49
- submit = st.button('Generate')
50
-
51
- #If generate button is clicked
52
  if submit:
53
-
54
- st.subheader("Answer:")
55
-
56
- st.write(response)
 
 
57
 
58
 
 
1
+ # import streamlit as st
2
+ # import langchain
3
+ # from langchain.llms import HuggingFaceHub
4
 
5
+ # #Function to return the response
6
+ # def load_answer(question):
7
+ # llm = HuggingFaceHub(repo_id="google/flan-t5-large")
8
+ # answer=llm(question)
9
+ # return answer
10
 
11
 
12
+ # #App UI starts here
13
+ # st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
14
+ # st.header("LangChain Demo")
15
 
16
+ # #Gets the user input
17
+ # def get_text():
18
+ # input_text = st.text_input("You: ", key="input")
19
+ # return input_text
20
 
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
+
30
+ # st.subheader("Answer:")
31
+
32
+ # st.write(response)
33
 
 
34
 
 
 
35
 
36
+ # #App UI starts here
37
+ # st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
38
+ # st.header("LangChain Demo")
39
 
40
+ # #Gets the user input
41
+ # def get_text():
42
+ # input_text = st.text_input("You: ", key="input")
43
+ # return input_text
44
 
45
 
46
+ # user_input=get_text()
47
+ # response = load_answer(user_input)
48
 
49
+ # submit = st.button('Generate')
50
+
51
+ # #If generate button is clicked
52
+ # if submit:
53
+
54
+ # st.subheader("Answer:")
55
+
56
+ # st.write(response)
57
+ import streamlit as st
58
+ from langchain.llms import HuggingFaceHub
59
+
60
+ # Function to return the response
61
+ def load_answer(question):
62
+ if not question:
63
+ return "Please ask a question."
64
+
65
+ # Initialize the Hugging Face model
66
+ llm = HuggingFaceHub(repo_id="google/flan-t5-large",
67
+ model_kwargs={"temperature": 0.7})
68
+
69
+ # Get response from the model
70
+ answer = llm(question)
71
+
72
+ return answer
73
+
74
+ # App UI starts here
75
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
76
  st.header("LangChain Demo")
77
 
78
+ # Gets the user input
79
  def get_text():
80
  input_text = st.text_input("You: ", key="input")
81
  return input_text
82
 
83
+ user_input = get_text()
84
+ submit = st.button('Generate')
85
 
86
+ # If the generate button is clicked
 
 
 
 
 
87
  if submit:
88
+ if user_input:
89
+ response = load_answer(user_input)
90
+ st.subheader("Answer:")
91
+ st.write(response)
92
+ else:
93
+ st.error("Please enter a question!")
94
 
95