File size: 1,118 Bytes
33ad83c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import streamlit as st


from dotenv import load_dotenv
from langchain.llms import HuggingFaceEndpoint

load_dotenv()

os.environ["HUGGINGFACEHUB_API_TOKEN"]=os.getenv("HF_TOKEN")

huggingface_token = os.environ["HUGGINGFACEHUB_API_TOKEN"]

#Function to return the response
def load_answer(question):
    # "text-davinci-003" model is depreciated, so using the latest one https://platform.openai.com/docs/deprecations
    if question:
        llm = HuggingFaceEndpoint(repo_id="mistralai/Mistral-7B-Instruct-v0.2")

        #Last week langchain has recommended to use invoke function for the below please :)
        answer=llm.invoke(question)
        return answer


#App UI starts here
st.set_page_config(page_title="LangChain Demo - Mistral", page_icon=":robot:")
st.header("LangChain Demo - Mistral")

#Gets the user input
def get_text():
    input_text = st.text_input("You: ", key="input")
    return input_text


user_input=get_text()
response = load_answer(user_input)

submit = st.button('Generate')  

#If generate button is clicked
if submit:

    st.subheader("Answer:")

    st.write(response)