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

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)