MatheusHRV commited on
Commit
e215e00
1 Parent(s): de29e7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py CHANGED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.llms import OpenAI
7
+
8
+ #When deployed on huggingface spaces, this values has to be passed using Variables & Secrets setting, as shown in the video :)
9
+ #import os
10
+ #os.environ["OPENAI_API_KEY"] = "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"
11
+
12
+ #Function to return the response
13
+ def load_answer(question):
14
+ # "text-davinci-003" model is depreciated, so using the latest one https://platform.openai.com/docs/deprecations
15
+ llm = OpenAI(model_name="gpt-3.5-turbo-instruct",temperature=0)
16
+ answer=llm(question)
17
+ return answer
18
+
19
+
20
+ #App UI starts here
21
+ st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
22
+ st.header("LangChain Demo")
23
+
24
+ #Gets the user input
25
+ def get_text():
26
+ input_text = st.text_input("You: ", key="input")
27
+ return input_text
28
+
29
+
30
+ user_input=get_text()
31
+ response = load_answer(user_input)
32
+
33
+ submit = st.button('Generate')
34
+
35
+ #If generate button is clicked
36
+ if submit:
37
+
38
+ st.subheader("Answer:")
39
+
40
+ st.write(response)