Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,45 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import requests
|
3 |
-
from transformers import pipeline
|
4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
print("Hugging Face Token:", HUGGINGFACE_TOKEN) # Debugging line
|
9 |
|
10 |
-
|
11 |
-
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-v0.1",
|
12 |
-
use_auth_token=HUGGINGFACE_TOKEN)
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
user_input = st.text_input("You: ", "Who are you?")
|
19 |
|
20 |
-
|
21 |
-
if user_input:
|
22 |
-
response = pipe(user_input)
|
23 |
-
generated_text = response[0]['generated_text'] # Adjust according to the response format
|
24 |
-
st.text_area("Bot:", generated_text, height=200)
|
25 |
-
else:
|
26 |
-
st.warning("Please enter a message.")
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
from langchain.llms import HuggingFaceEndpoint
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"]=os.getenv("HF_TOKEN")
|
11 |
+
|
12 |
+
huggingface_token = os.environ["HUGGINGFACEHUB_API_TOKEN"]
|
13 |
+
|
14 |
+
#Function to return the response
|
15 |
+
def load_answer(question):
|
16 |
+
# "text-davinci-003" model is depreciated, so using the latest one https://platform.openai.com/docs/deprecations
|
17 |
+
if question:
|
18 |
+
llm = HuggingFaceEndpoint(repo_id="mistralai/Mistral-7B-Instruct-v0.2")
|
19 |
+
|
20 |
+
#Last week langchain has recommended to use invoke function for the below please :)
|
21 |
+
answer=llm.invoke(question)
|
22 |
+
return answer
|
23 |
+
|
24 |
+
|
25 |
+
#App UI starts here
|
26 |
+
st.set_page_config(page_title="LangChain Demo - Mistral", page_icon=":robot:")
|
27 |
+
st.header("LangChain Demo - Mistral")
|
28 |
+
|
29 |
+
#Gets the user input
|
30 |
+
def get_text():
|
31 |
+
input_text = st.text_input("You: ", key="input")
|
32 |
+
return input_text
|
33 |
+
|
34 |
|
35 |
+
user_input=get_text()
|
36 |
+
response = load_answer(user_input)
|
|
|
37 |
|
38 |
+
submit = st.button('Generate')
|
|
|
|
|
39 |
|
40 |
+
#If generate button is clicked
|
41 |
+
if submit:
|
42 |
|
43 |
+
st.subheader("Answer:")
|
|
|
44 |
|
45 |
+
st.write(response)
|
|
|
|
|
|
|
|
|
|
|
|