abhinandan18 commited on
Commit
0e3a02a
1 Parent(s): 19ae0ba
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import streamlit as st
5
+ import os
6
+ #from langchain import HuggingFaceHub
7
+ from langchain_community.llms import HuggingFaceEndpoint
8
+ from langchain.chains import LLMChain
9
+ from langchain.prompts import PromptTemplate
10
+
11
+
12
+
13
+ print(os.environ["HUGGINGFACEHUB_API_TOKEN"])
14
+ def get_llm_response(question):
15
+
16
+ HUGGINGFACEHUB_API_TOKEN=os.environ["HUGGINGFACEHUB_API_TOKEN"]
17
+ repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
18
+
19
+
20
+
21
+ template = """Question: {question}
22
+
23
+ Answer: """
24
+
25
+ prompt = PromptTemplate.from_template(template)
26
+
27
+
28
+ llm = HuggingFaceEndpoint(
29
+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN
30
+ )
31
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
32
+ answer=llm_chain.run(question)
33
+ print(answer)
34
+
35
+ return answer
36
+
37
+ ##initialize streamlit
38
+ st.set_page_config(page_title="Q&A Demo")
39
+ st.header("Langchain application")
40
+
41
+ question=st.text_input("input: ",key="input")
42
+
43
+ response=get_llm_response(question)
44
+ submit=st.button("Ask the question")
45
+
46
+
47
+ #if submit is clicked
48
+
49
+ if submit:
50
+ st.subheader("The response is")
51
+ st.write(response)
52
+
53
+