File size: 1,143 Bytes
0e3a02a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from dotenv import load_dotenv
load_dotenv()

import streamlit as st
import os
#from langchain import HuggingFaceHub
from langchain_community.llms import HuggingFaceEndpoint
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate



print(os.environ["HUGGINGFACEHUB_API_TOKEN"])
def get_llm_response(question):
    
    HUGGINGFACEHUB_API_TOKEN=os.environ["HUGGINGFACEHUB_API_TOKEN"]
    repo_id = "mistralai/Mistral-7B-Instruct-v0.2"



    template = """Question: {question}

    Answer: """

    prompt = PromptTemplate.from_template(template)


    llm = HuggingFaceEndpoint(
        repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN
    )
    llm_chain = LLMChain(prompt=prompt, llm=llm)
    answer=llm_chain.run(question)
    print(answer)

    return answer

##initialize streamlit 
st.set_page_config(page_title="Q&A Demo")
st.header("Langchain application")

question=st.text_input("input: ",key="input")

response=get_llm_response(question)
submit=st.button("Ask the question")


#if submit is clicked

if submit:
    st.subheader("The response is")
    st.write(response)