Nullzero commited on
Commit
88b9f42
·
1 Parent(s): ff9fed3

Add application file

Browse files
Files changed (2) hide show
  1. app.py +80 -0
  2. requirements.txt +28 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Python file to serve as the frontend"""
2
+ import streamlit as st
3
+ from streamlit_chat import message
4
+ import os
5
+ import openai
6
+
7
+
8
+ #Import LLM wrapper
9
+ from langchain.llms import OpenAI
10
+ #Import Prompt Template
11
+ from langchain.prompts import PromptTemplate
12
+ #Import chains
13
+ from langchain.chains import LLMChain
14
+ #Import Sequential Chains
15
+ from langchain.chains import SimpleSequentialChain
16
+
17
+
18
+
19
+ def load_chain():
20
+ os.environ["OPENAI_API_KEY"] = api_key
21
+ llm = OpenAI(temperature=0.3)
22
+ #user_in = input("Please describe your Python project in one to two sentences: ")
23
+
24
+ first_prompt = PromptTemplate(
25
+ input_variables=["user_in"],
26
+ template= "You are a senior Python Engineer. List five steps required to develop the software project specified. Use the common libraries available in Python3. Be verbose in the code and opinionated about framework choice.:\n\n {user_in}"
27
+ )
28
+ #First chain
29
+ chain = LLMChain(llm=llm, prompt=first_prompt)
30
+
31
+ second_prompt = PromptTemplate(
32
+ input_variables=["project"],
33
+ template= "Produce the python3 code for each step of the software {project} described. Use appropriate style, classes and variables. Be verbose."
34
+ )
35
+
36
+ chain_two = LLMChain(llm=llm, prompt=second_prompt)
37
+
38
+ overall_chain = SimpleSequentialChain(chains=[chain, chain_two], verbose=True)
39
+
40
+ code_output = overall_chain.run(user_in)
41
+
42
+ return chain
43
+
44
+ chain = load_chain()
45
+
46
+ # From here down is all the StreamLit UI.
47
+ st.set_page_config(page_title="Python Project Generator", page_icon=":robot:")
48
+ st.header("Python Project Generator")
49
+
50
+ if "generated" not in st.session_state:
51
+ st.session_state["generated"] = []
52
+
53
+ if "past" not in st.session_state:
54
+ st.session_state["past"] = []
55
+
56
+
57
+ def get_text():
58
+ user_input = st.text_input("Please describe your python project in 1-2 sentences", key="input")
59
+ return user_input, get_key
60
+
61
+ def get_key():
62
+ get_key = st.text_input("Please enter your OpenAPI API Key", key="input")
63
+ return get_key
64
+
65
+
66
+ api_key = get_key()
67
+ user_input = get_text()
68
+
69
+
70
+ if user_input:
71
+ output = chain.run(input=user_input)
72
+
73
+ st.session_state.past.append(user_input)
74
+ st.session_state.generated.append(output)
75
+
76
+ if st.session_state["generated"]:
77
+
78
+ for i in range(len(st.session_state["generated"]) - 1, -1, -1):
79
+ message(st.session_state["generated"][i], key=str(i))
80
+ message(st.session_state["past"][i], is_user=True, key=str(i) + "_user")
requirements.txt ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohttp==3.8.4
2
+ aiosignal==1.3.1
3
+ async-timeout==4.0.2
4
+ attrs==22.2.0
5
+ certifi==2022.12.7
6
+ charset-normalizer==3.1.0
7
+ dataclasses-json==0.5.7
8
+ frozenlist==1.3.3
9
+ greenlet==2.0.2
10
+ idna==3.4
11
+ langchain==0.0.118
12
+ marshmallow==3.19.0
13
+ marshmallow-enum==1.5.1
14
+ multidict==6.0.4
15
+ mypy-extensions==1.0.0
16
+ numpy==1.24.2
17
+ openai==0.27.2
18
+ packaging==23.0
19
+ pydantic==1.10.6
20
+ PyYAML==6.0
21
+ requests==2.28.2
22
+ SQLAlchemy==1.4.47
23
+ tenacity==8.2.2
24
+ tqdm==4.65.0
25
+ typing-inspect==0.8.0
26
+ typing_extensions==4.5.0
27
+ urllib3==1.26.15
28
+ yarl==1.8.2