Spaces:
Sleeping
Sleeping
Abhishek Srivastava
commited on
Commit
·
61d9ae2
1
Parent(s):
f750fb4
'v1'
Browse files- app.py +60 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.title("Falcon QA Bot")
|
4 |
+
|
5 |
+
# import chainlit as cl
|
6 |
+
|
7 |
+
import os
|
8 |
+
huggingfacehub_api_token = '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'
|
9 |
+
|
10 |
+
from langchain import HuggingFaceHub, PromptTemplate, LLMChain
|
11 |
+
|
12 |
+
repo_id = "tiiuae/falcon-7b-instruct"
|
13 |
+
llm = HuggingFaceHub(huggingfacehub_api_token=huggingfacehub_api_token,
|
14 |
+
repo_id=repo_id,
|
15 |
+
model_kwargs={"temperature":0.2, "max_new_tokens":2000})
|
16 |
+
|
17 |
+
template = """
|
18 |
+
You are an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.
|
19 |
+
|
20 |
+
{question}
|
21 |
+
|
22 |
+
"""
|
23 |
+
# input = st.text_input("What do you want to ask about", placeholder="Input your question here")
|
24 |
+
|
25 |
+
|
26 |
+
# # @cl.langchain_factory
|
27 |
+
# def factory():
|
28 |
+
# prompt = PromptTemplate(template=template, input_variables=['question'])
|
29 |
+
# llm_chain = LLMChain(prompt=prompt, llm=llm, verbose=True)
|
30 |
+
|
31 |
+
# return llm_chain
|
32 |
+
|
33 |
+
|
34 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
35 |
+
llm_chain = LLMChain(prompt=prompt,verbose=True,llm=llm)
|
36 |
+
|
37 |
+
# result = llm_chain.predict(question=input)
|
38 |
+
|
39 |
+
# print(result)
|
40 |
+
|
41 |
+
def chat(query):
|
42 |
+
# prompt = PromptTemplate(template=template, input_variables=["question"])
|
43 |
+
# llm_chain = LLMChain(prompt=prompt,verbose=True,llm=llm)
|
44 |
+
|
45 |
+
result = llm_chain.predict(question=query)
|
46 |
+
|
47 |
+
return result
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
def main():
|
53 |
+
input = st.text_input("What do you want to ask about", placeholder="Input your question here")
|
54 |
+
if input:
|
55 |
+
output = chat(input)
|
56 |
+
st.write(output,unsafe_allow_html=True)
|
57 |
+
|
58 |
+
|
59 |
+
if __name__ == '__main__':
|
60 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
langchain==0.0.173
|
2 |
+
llama_index==0.5.27
|
3 |
+
streamlit==1.22.0
|