sankar12345
commited on
Commit
•
15b5846
1
Parent(s):
fa499ec
Upload 3 files
Browse files- app.py +43 -0
- env-sample.txt +1 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.llms 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 |
+
#Function to return the response
|
14 |
+
def load_answer(question):
|
15 |
+
llm = HuggingFaceEndpoint(
|
16 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.2") # Model link : https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2
|
17 |
+
|
18 |
+
answer=llm.invoke(question)
|
19 |
+
return answer
|
20 |
+
|
21 |
+
|
22 |
+
#App UI starts here
|
23 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
24 |
+
st.header("LangChain Demo by Sankar")
|
25 |
+
|
26 |
+
#Gets the user input
|
27 |
+
def get_text():
|
28 |
+
input_text = st.text_input("You: ", key="input")
|
29 |
+
return input_text
|
30 |
+
|
31 |
+
|
32 |
+
user_input=get_text()
|
33 |
+
response = load_answer(user_input)
|
34 |
+
|
35 |
+
submit = st.button('Generate')
|
36 |
+
|
37 |
+
#If generate button is clicked
|
38 |
+
if submit:
|
39 |
+
|
40 |
+
st.subheader("Answer:")
|
41 |
+
|
42 |
+
st.write(response)
|
43 |
+
|
env-sample.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
HUGGINGFACEHUB_API_TOKEN=""
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain==0.2.5
|
2 |
+
huggingface-hub==0.23.4
|
3 |
+
streamlit==1.36.0
|
4 |
+
langchain_community==0.2.9
|