-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlang_chain_app_14_lines.py
30 lines (25 loc) · 1.02 KB
/
lang_chain_app_14_lines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st
from langchain.llms import OpenAI
st.title("ChatGPT Clone")
# Input for OpenAI API Key
openai_api_key = st.sidebar.text_input('Enter OpenAI API Key', type='password')
# Function to generate response
def generate_response(input_text):
if not openai_api_key.startswith('sk-'):
st.warning('Please enter a valid OpenAI API key')
elif not input_text:
st.warning('Please enter some text')
else:
llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key)
with st.spinner("Generating response..."):
response = llm(input_text)
st.info("Generated Response:")
st.write(response)
# Streamlit form for user input
with st.form('my_form'):
st.header("Enter Text")
text = st.text_area("Input:", "What are the three pieces of advice for learning how to code?")
submit_button = st.form_submit_button(label='Generate Response')
# Generate response when the form is submitted
if submit_button:
generate_response(text)