zainikhan34 commited on
Commit
c87d15c
·
verified ·
1 Parent(s): 63f3930

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -38
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
- huggingfacehub_api_token=os.getenv('HUGGINGFACEHUB_API_TOKEN'),
14
- model_kwargs={
15
- 'temperature': 0.6,
16
- 'max_length': 1000
17
- }
18
- )
19
- # input_data = {"context": context, "question": question}
20
- # response = llm(input_data)
21
- prompt = f"Context: {context}\nQuestion: {question}\nAnswer:"
22
- response = llm(prompt)
23
- return response
24
-
25
- ## Initialize our Streamlit app
26
- st.set_page_config(page_title="Q&A Demo")
27
-
28
- st.header("Langchain Application")
29
-
30
- context = st.text_area("Context: ", key="context")
31
- question = st.text_input("Question: ", key="question")
32
- submit = st.button("Ask the question")
33
-
34
- ## If ask button is clicked
35
- if submit:
36
- response = get_ai_response(context, question)
37
- st.subheader("The Response is")
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)