Spaces:
Configuration error
Configuration error
Delete app.py
Browse filesremove previous version of the app.
app.py
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from langchain.llms import OpenAI
|
3 |
-
from langchain.chains import PALChain
|
4 |
-
from langchain.chains.llm import LLMChain
|
5 |
-
|
6 |
-
# set page config
|
7 |
-
st.set_page_config(page_title="๐ฆ๐ This is a Program Aided Language model")
|
8 |
-
st.title("๐ฆ๐๐งฎ Program Aided Language Model: Helps with math problems")
|
9 |
-
st.markdown(
|
10 |
-
"""This example was adapt from Data Professor Github [repo](https://github.com/dataprofessor/langchain-quickstart/blob/master/streamlit_app.py)"""
|
11 |
-
)
|
12 |
-
st.markdown(
|
13 |
-
"""Paper: [Program-Aided Language Models for Program Synthesis](https://arxiv.org/pdf/2211.10435.pdf)"""
|
14 |
-
)
|
15 |
-
st.markdown(
|
16 |
-
"""Credit: [Sam Witteveen](https://www.youtube.com/playlist?list=PL8motc6AQftk1Bs42EW45kwYbyJ4jOdiZ)"""
|
17 |
-
)
|
18 |
-
|
19 |
-
# sidebar for OpenAI API key
|
20 |
-
openai_api_key = st.sidebar.text_input("Enter your OpenAI API key", type="password")
|
21 |
-
|
22 |
-
|
23 |
-
def generate_response(input_text):
|
24 |
-
"""
|
25 |
-
Generates response to input text using PALChain
|
26 |
-
|
27 |
-
Parameters
|
28 |
-
----------
|
29 |
-
input_text : str
|
30 |
-
Input text to generate response for using PALChain
|
31 |
-
|
32 |
-
Returns
|
33 |
-
-------
|
34 |
-
None
|
35 |
-
|
36 |
-
Example
|
37 |
-
-------
|
38 |
-
"""
|
39 |
-
llm = OpenAI(temperature=0, openai_api_key=openai_api_key, max_tokens=512, skip_on_failure=True)
|
40 |
-
pal_chain = PALChain.from_math_prompt(llm, verbose=True)
|
41 |
-
st.write(pal_chain.run(input_text))
|
42 |
-
|
43 |
-
|
44 |
-
with st.form("my_form"):
|
45 |
-
text = st.text_area(
|
46 |
-
"Enter text:",
|
47 |
-
"Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?",
|
48 |
-
)
|
49 |
-
submitted = st.form_submit_button("Submit")
|
50 |
-
if not openai_api_key.startswith("sk-"):
|
51 |
-
st.warning("Please enter your OpenAI API key!", icon="โ ")
|
52 |
-
if submitted and openai_api_key.startswith("sk-"):
|
53 |
-
generate_response(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|