Spaces:
Runtime error
Runtime error
Ravi theja K
commited on
Commit
•
bc1a7ea
1
Parent(s):
a7ab1c1
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
#As Langchain team has been working aggresively on improving the tool, we can see a lot of changes happening every weeek,
|
7 |
+
#As a part of it, the below import has been depreciated
|
8 |
+
#from langchain.llms import OpenAI
|
9 |
+
|
10 |
+
#New import from langchain, which replaces the above
|
11 |
+
from langchain_openai import OpenAI
|
12 |
+
|
13 |
+
#When deployed on huggingface spaces, this values has to be passed using Variables & Secrets setting, as shown in the video :)
|
14 |
+
#import os
|
15 |
+
#os.environ["OPENAI_API_KEY"] = "sk-PLfFwPq6y24234234234FJ1Uc234234L8hVowXdt"
|
16 |
+
|
17 |
+
#Function to return the response
|
18 |
+
def load_answer(question):
|
19 |
+
# "text-davinci-003" model is depreciated, so using the latest one https://platform.openai.com/docs/deprecations
|
20 |
+
llm = OpenAI(model_name="gpt-3.5-turbo-instruct",temperature=0)
|
21 |
+
|
22 |
+
#Last week langchain has recommended to use invoke function for the below please :)
|
23 |
+
answer=llm.invoke(question)
|
24 |
+
return answer
|
25 |
+
|
26 |
+
|
27 |
+
#App UI starts here
|
28 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
29 |
+
st.header("LangChain Demo")
|
30 |
+
|
31 |
+
#Gets the user input
|
32 |
+
def get_text():
|
33 |
+
input_text = st.text_input("You: ", key="input")
|
34 |
+
return input_text
|
35 |
+
|
36 |
+
|
37 |
+
user_input=get_text()
|
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)
|