Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain.llms import OpenAI
|
| 3 |
+
|
| 4 |
+
st.title('🦜🔗 OpenAI LLM Prompting')
|
| 5 |
+
|
| 6 |
+
openai_api_key = st.sidebar.text_input('OpenAI API Key', type='password')
|
| 7 |
+
|
| 8 |
+
def generate_response(input_text):
|
| 9 |
+
llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key)
|
| 10 |
+
st.info(llm(input_text))
|
| 11 |
+
|
| 12 |
+
with st.form('my_form'):
|
| 13 |
+
text = st.text_area('Enter text:', 'What are the three key pieces of advice for learning how to code?')
|
| 14 |
+
submitted = st.form_submit_button('Submit')
|
| 15 |
+
if not openai_api_key.startswith('sk-'):
|
| 16 |
+
st.warning('Please enter your OpenAI API key!', icon='⚠')
|
| 17 |
+
if submitted and openai_api_key.startswith('sk-'):
|
| 18 |
+
generate_response(text)
|