Spaces:
Runtime error
Runtime error
Commit ·
bd1c309
1
Parent(s): 4cdf418
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import streamlit as stst.title("Falcon QA Bot")# import chainlit as climport oshuggingfacehub_api_token = st.secrets["hf_token"]from langchain import HuggingFaceHub, PromptTemplate, LLMChainrepo_id = "tiiuae/falcon-7b-instruct"llm = HuggingFaceHub(huggingfacehub_api_token=huggingfacehub_api_token,repo_id=repo_id,model_kwargs={"temperature":0.2, "max_new_tokens":2000})template = """You are an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.{question}"""# input = st.text_input("What do you want to ask about", placeholder="Input your question here")# # @cl.langchain_factory# def factory():# prompt = PromptTemplate(template=template, input_variables=['question'])# llm_chain = LLMChain(prompt=prompt, llm=llm, verbose=True)# return llm_chainprompt = PromptTemplate(template=template, input_variables=["question"])llm_chain = LLMChain(prompt=prompt,verbose=True,llm=llm)# result = llm_chain.predict(question=input)# print(result)def chat(query):# prompt = PromptTemplate(template=template, input_variables=["question"])# llm_chain = LLMChain(prompt=prompt,verbose=True,llm=llm)result = llm_chain.predict(question=query)return resultdef main():input = st.text_input("What do you want to ask about", placeholder="Input your question here")if input:output = chat(input)st.write(output,unsafe_allow_html=True)if __name__ == '__main__':main()123456789101112131415161718192021222324252627282930313233343536373839import streamlit as stfrom transformers import pipelinefrom collections import deque# Configure system promptsystem_prompt = "You are an AI assistant that specializes in helping with code-based questions and tasks. Feel free to ask anything related to coding!"st.title("Falcon QA Bot")@st.cache(allow_output_mutation=True)def get_qa_pipeline():return pipeline("question-answering", model="tiiuae/falcon-7b-instruct", device=0)def chat(query):pipeline = get_qa_pipeline()result = pipeline(question=query, max_length=2000, context=system_prompt)return resultdef main():user_queue = deque()st.markdown('<style>div.row-widget.stRadio > div{flex-direction:row;}</style>', unsafe_allow_html=True)input = st.text_area("What do you want to ask about", value="", height=150, max_chars=500, key="input")if st.button("Ask"):if input:user_queue.append(input)if user_queue:current_user = user_queue[0]st.text_area("System Prompt", value=system_prompt, height=150, disabled=True)st.text_area("User Input", value=current_user, height=150, disabled=True)with st.spinner("Generating response..."):output = chat(current_user)st.text_area("Falcon's Answer", value=output["answer"], height=150, disabled=True)user_queue.popleft()if __name__ == '__main__':main()
app.py+28-49