Spaces:
Configuration error
Configuration error
File size: 1,765 Bytes
a2f545d 6875bc4 a2f545d |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import streamlit as st
from langchain.llms import OpenAI
from langchain.chains import PALChain
from langchain.chains.llm import LLMChain
# set page config
st.set_page_config(page_title="๐ฆ๐ This is a Program Aided Language model")
st.title("๐ฆ๐๐งฎ Program Aided Language Model: Helps with math problems")
st.markdown(
"""This example was adapt from Data Professor Github [repo](https://github.com/dataprofessor/langchain-quickstart/blob/master/streamlit_app.py)"""
)
st.markdown(
"""Paper: [Program-Aided Language Models for Program Synthesis](https://arxiv.org/pdf/2211.10435.pdf)"""
)
st.markdown(
"""Credit: [Sam Witteven](https://www.youtube.com/playlist?list=PL8motc6AQftk1Bs42EW45kwYbyJ4jOdiZ)"""
)
# sidebar for OpenAI API key
openai_api_key = st.sidebar.text_input("Enter your OpenAI API key", type="password")
def generate_response(input_text):
"""
Generates response to input text using PALChain
Parameters
----------
input_text : str
Input text to generate response for using PALChain
Returns
-------
None
Example
-------
"""
llm = OpenAI(temperature=0, openai_api_key=openai_api_key, max_tokens=512, skip_on_failure=True)
pal_chain = PALChain.from_math_prompt(llm, verbose=True)
st.write(pal_chain.run(input_text))
with st.form("my_form"):
text = st.text_area(
"Enter text:",
"Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?",
)
submitted = st.form_submit_button("Submit")
if not openai_api_key.startswith("sk-"):
st.warning("Please enter your OpenAI API key!", icon="โ ")
if submitted and openai_api_key.startswith("sk-"):
generate_response(text)
|