Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
#from langchain_openai import OpenAI
|
4 |
+
#from langchain.llms import HuggingFaceEndpoint
|
5 |
+
from langchain_community.llms import HuggingFaceEndpoint
|
6 |
+
|
7 |
+
#When deployed on huggingface spaces, this values has to be passed using Variables & Secrets setting, as shown in the video :)
|
8 |
+
#import os
|
9 |
+
#os.environ["OPENAI_API_KEY"] = "sk-PLfFwPq6y24234234234FJ1Uc234234L8hVowXdt"
|
10 |
+
|
11 |
+
#Function to return the response
|
12 |
+
def load_answer(question):
|
13 |
+
# "text-davinci-003" model is depreciated, so using the latest one https://platform.openai.com/docs/deprecations
|
14 |
+
#llm = OpenAI(model_name="gpt-3.5-turbo-instruct",temperature=0)
|
15 |
+
llm = HuggingFaceEndpoint(repo_id="mistralai/Mistral-7B-Instruct-v0.2", Temperature=0.9)
|
16 |
+
#Last week langchain has recommended to use invoke function for the below please :)
|
17 |
+
answer=llm.invoke(question)
|
18 |
+
return answer
|
19 |
+
|
20 |
+
|
21 |
+
#App UI starts here
|
22 |
+
st.set_page_config(page_title="Sentiment Analysis", page_icon=":robot:")
|
23 |
+
st.header("Sentiment Analysis")
|
24 |
+
|
25 |
+
#Gets the user input
|
26 |
+
def get_text():
|
27 |
+
input_text = st.text_input("You:", "Pls Write Your Something.......")
|
28 |
+
if input_text.isalpha():
|
29 |
+
st.write(text, 'string', )
|
30 |
+
else:
|
31 |
+
st.write('Please type in a string Only')
|
32 |
+
return input_text
|
33 |
+
|
34 |
+
user_input=get_text()
|
35 |
+
response = load_answer(user_input)
|
36 |
+
|
37 |
+
submit = st.button('Generate')
|
38 |
+
|
39 |
+
#If generate button is clicked
|
40 |
+
if submit:
|
41 |
+
|
42 |
+
st.subheader("Answer:")
|
43 |
+
|
44 |
+
st.write(response)
|