Spaces:
Sleeping
Sleeping
Commit
•
02936e2
1
Parent(s):
a16f81d
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
from langchain.llms import HuggingFaceEndpoint
|
5 |
+
|
6 |
+
#Function to return the response
|
7 |
+
def load_answer(question):
|
8 |
+
llm = HuggingFaceEndpoint(repo_id="mistralai/Mistral-7B-Instruct-v0.2") # Model link : https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2
|
9 |
+
|
10 |
+
#Last week langchain has recommended to use invoke function for the below please :)
|
11 |
+
answer=llm.invoke(question)
|
12 |
+
return answer
|
13 |
+
|
14 |
+
|
15 |
+
#App UI starts here
|
16 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
17 |
+
st.header("LangChain Demo")
|
18 |
+
|
19 |
+
#Gets the user input
|
20 |
+
def get_text():
|
21 |
+
input_text = st.text_input("You: ", key="input")
|
22 |
+
return input_text
|
23 |
+
|
24 |
+
|
25 |
+
user_input=get_text()
|
26 |
+
response = load_answer(user_input)
|
27 |
+
|
28 |
+
submit = st.button('Generate')
|
29 |
+
|
30 |
+
#If generate button is clicked
|
31 |
+
if submit:
|
32 |
+
|
33 |
+
st.subheader("Answer:")
|
34 |
+
|
35 |
+
st.write(response)
|
36 |
+
|