Spaces:
Sleeping
Sleeping
vismaya2939
commited on
Commit
•
c3037a8
1
Parent(s):
142af47
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#Hello! It seems like you want to import the Streamlit library in Python. Streamlit is a powerful open-source framework used for building web applications with interactive data visualizations and machine learning models. To import Streamlit, you'll need to ensure that you have it installed in your Python environment.
|
2 |
+
#Once you have Streamlit installed, you can import it into your Python script using the import statement,
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
from langchain_openai import OpenAI
|
7 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
8 |
+
|
9 |
+
#When deployed on huggingface spaces, this values has to be passed using Variables & Secrets setting, as shown in the video :)
|
10 |
+
#import os
|
11 |
+
#os.environ["OPENAI_API_KEY"] = "sk-PLfFwPq6y24234234234FJ1Uc234234L8hVowXdt"
|
12 |
+
|
13 |
+
import os
|
14 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "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"
|
15 |
+
|
16 |
+
#Function to return the response
|
17 |
+
def load_answer(question):
|
18 |
+
#llm = OpenAI(model_name="gpt-3.5-turbo-instruct",temperature=0)
|
19 |
+
llm = HuggingFaceEndpoint(
|
20 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.3") # Model link : https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3
|
21 |
+
|
22 |
+
answer=llm.invoke(question)
|
23 |
+
return answer
|
24 |
+
|
25 |
+
|
26 |
+
#App UI starts here
|
27 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
28 |
+
st.header("LangChain Demo")
|
29 |
+
|
30 |
+
#Gets the user input
|
31 |
+
def get_text():
|
32 |
+
input_text = st.text_input("You: ", key="input")
|
33 |
+
return input_text
|
34 |
+
|
35 |
+
|
36 |
+
user_input=get_text()
|
37 |
+
if user_input!= "":
|
38 |
+
response = load_answer(user_input)
|
39 |
+
|
40 |
+
submit = st.button('Generate')
|
41 |
+
|
42 |
+
#If generate button is clicked
|
43 |
+
if submit:
|
44 |
+
|
45 |
+
st.subheader("Answer:")
|
46 |
+
|
47 |
+
st.write(response)
|
48 |
+
|