3v324v23 commited on
Commit
f69aeb0
·
1 Parent(s): e47278e
Files changed (2) hide show
  1. app.py +220 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import streamlit as st
4
+ from langchain.agents import load_tools, initialize_agent
5
+ from langchain.llms import OpenAI
6
+ import time
7
+ from streamlit_option_menu import option_menu
8
+ def initialize_tools_and_agent(openai_api_key):
9
+ llm = OpenAI(temperature=0,openai_api_key=openai_api_key)
10
+ tools = load_tools(["llm-math"], llm=llm)
11
+ agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
12
+ return agent
13
+
14
+ # Set Streamlit page configuration
15
+ st.set_page_config(page_title='Math ChatGPT4',
16
+ page_icon=":memo:",
17
+ layout='wide',
18
+ initial_sidebar_state='collapsed')
19
+ st.title('Mathematical Puzzles Solving Tool')
20
+ #st.header('Language Model App. for Mathematical Puzzle Solver')
21
+ # Set CSS properties for HTML components
22
+ st.markdown("""
23
+ <style>
24
+ body {
25
+ color: #ff0;
26
+ background-color: #4f8bf9;
27
+ }
28
+ h1, h2 {
29
+ color: #000000;
30
+ }
31
+ </style>
32
+ """, unsafe_allow_html=True)
33
+
34
+ hide_style='''
35
+ <style>
36
+ #MainMenu {visibility:hidden;}
37
+ footer {visibility:hidden;}
38
+ .css-hi6a2p {padding-top: 0rem;}
39
+ head {visibility:hidden;}
40
+ </style>
41
+ '''
42
+
43
+ with st.sidebar:
44
+ selected = option_menu("Main Menu", ["Home", 'Help'],
45
+ icons=['house', 'gear'], menu_icon="cast", default_index=0)
46
+ selected
47
+ hide_style='''
48
+ <style>
49
+ #MainMenu {visibility:hidden;}
50
+ footer {visibility:hidden;}
51
+ .css-hi6a2p {padding-top: 0rem;}
52
+ head {visibility:hidden;}
53
+ </style>
54
+ '''
55
+ hide_streamlit_style = """
56
+ <style>
57
+ div[data-testid="stToolbar"] {
58
+ visibility: hidden;
59
+ height: 0%;
60
+ position: fixed;
61
+ }
62
+ div[data-testid="stDecoration"] {
63
+ visibility: hidden;
64
+ height: 0%;
65
+ position: fixed;
66
+ }
67
+ div[data-testid="stStatusWidget"] {
68
+ visibility: hidden;
69
+ height: 0%;
70
+ position: fixed;
71
+ }
72
+ #MainMenu {
73
+ visibility: hidden;
74
+ height: 0%;
75
+ }
76
+ header {
77
+ visibility: hidden;
78
+ height: 0%;
79
+ }
80
+ footer {
81
+ visibility: hidden;
82
+ height: 0%;
83
+ }
84
+ </style>
85
+ """
86
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
87
+ st.markdown("""
88
+ <style>
89
+ .footer {
90
+ position: fixed;
91
+ left: 0;
92
+ bottom: 0;
93
+ width: 100%;
94
+ background-color: #f8f9fa;
95
+ color: black;
96
+ text-align: center;
97
+ padding: 10px;
98
+ }
99
+ </style>
100
+
101
+ <div class="footer">
102
+ <p>Copyright &copy; 2023 AI-Books. All Rights Reserved.</p>
103
+ </div>
104
+ """, unsafe_allow_html=True)
105
+
106
+ if selected=="Help":
107
+
108
+ st.markdown(hide_style,unsafe_allow_html=True)
109
+ # st.title("Help")
110
+ # Import required libraries
111
+ import streamlit as st
112
+
113
+ # Set Streamlit page configuration
114
+ #st.set_page_config(page_title='Help - XLS Office Documents Analysis with ChatGPT4 NLP Model',
115
+ # page_icon=":memo:",
116
+ # layout='wide',
117
+ # initial_sidebar_state='collapsed')
118
+
119
+ import streamlit as st
120
+
121
+ # Set CSS properties for HTML components
122
+ st.markdown("""
123
+ <style>
124
+ body {
125
+ color: #000;
126
+ background-color: #f0f0f0;
127
+ font-family: Arial, sans-serif;
128
+ }
129
+ h1, h2 {
130
+ color: #ff6600;
131
+ text-align: center;
132
+ }
133
+ </style>
134
+ """, unsafe_allow_html=True)
135
+
136
+ # Display application title
137
+ # st.markdown("""
138
+ # <h1>ChatGPT-4 Bot: Puzzle Solving and Imagination Companion</h1>
139
+ # <h2>Your Partner for Puzzles and Creative Adventures</h2>
140
+ # """, unsafe_allow_html=True)
141
+
142
+ ## Display authorship details
143
+ # st.markdown("""
144
+ ## Developed by [Your Name]
145
+ # * AI Enthusiast
146
+ # * Expert in AI-driven Conversations
147
+ # """, unsafe_allow_html=True)
148
+
149
+ # Display application introduction
150
+ st.markdown("""
151
+ ### Welcome to ChatGPT-4 Bot!
152
+
153
+ Introducing your versatile AI companion, ChatGPT-4 Bot. This interactive tool is designed to be your guide for solving mathematical puzzles . Whether you're a curious kid, a young learner, or simply looking to exercise your mind, ChatGPT-4 Bot is here to assist.
154
+
155
+ ### Dive into Puzzle Challenges
156
+
157
+ Are math puzzles your thing? ChatGPT-4 Bot is equipped to help you tackle a variety of mathematical challenges. From solving equations to deciphering number patterns, this AI-powered tool is your partner in puzzle-solving.
158
+ ### How to Interact
159
+
160
+ Puzzles Mode: Input math-related questions or challenges and receive step-by-step solutions.
161
+
162
+ ### Who Can Benefit
163
+
164
+ - Students seeking assistance with math problems
165
+
166
+ - Curious minds interested in AI-driven conversations
167
+
168
+ ### Get in Touch
169
+
170
+ If you have any inquiries or suggestions, don't hesitate to get in touch. Let's embark on a journey of exploration and learning together!
171
+ """, unsafe_allow_html=True)
172
+
173
+
174
+ #-----------------
175
+
176
+ hide_style='''
177
+ <style>
178
+ #MainMenu {visibility:hidden;}
179
+ footer {visibility:hidden;}
180
+ .css-hi6a2p {padding-top: 0rem;}
181
+ head {visibility:hidden;}
182
+ </style>
183
+ '''
184
+ st.markdown(hide_style,unsafe_allow_html=True)
185
+ if selected=="Home":
186
+ openai_api_key = st.sidebar.text_input('OpenAI API Key', type="password")
187
+ question_examples = [
188
+ "A store sells oranges in packs of 5 and apples in packs of 8. If John bought 7 packs of oranges and 4 packs of apples, how many fruits did he buy in total?",
189
+ "A box contains 24 red balls and 36 blue balls. If 30% of the red balls and 40% of the blue balls are removed, how many balls are left in the box?",
190
+ "A company has 800 employees. If 25% of the employees are managers and the rest are regular employees, how many regular employees are there in the company?",
191
+ "A classroom has a total of 35 students. If 40% of the students are boys, how many girls are there in the classroom?",
192
+ # Add more examples as needed
193
+ ]
194
+
195
+ # Dropdown select box for question examples
196
+ selected_example = st.selectbox('Choose a question example:', question_examples)
197
+
198
+ # Pre-populate the question field with the selected example
199
+ # question = st.text_input('Enter your question:', value=selected_example)
200
+ math_question = st.text_area("selected example or write any puzzle and press enter:", value=selected_example)
201
+ if not openai_api_key or not openai_api_key.startswith('sk-'):
202
+ st.warning('Please enter your OpenAI API key!', icon='⚠️')
203
+ else:
204
+ if st.button('Solve'):
205
+ try:
206
+ agent = initialize_tools_and_agent(openai_api_key)
207
+ response = agent.run(math_question)
208
+ with st.spinner('Solving...'):
209
+ time.sleep(2) # Simulate processing time
210
+ st.success('Solved!')
211
+ st.markdown(f"**The Solution Is:**\n\n{response}")
212
+ if(response=="Agent stopped due to iteration limit or time limit."):
213
+ st.warning('Please enter your Puzzle!mathmatical tool', icon='⚠️')
214
+ except openai.error.OpenAIError as e:
215
+ #st.error(f"An error occurred: {e}")
216
+ st.warning('Please enter your puzzle! mathmatical tool', icon='⚠️')
217
+ except Exception as e:
218
+ #st.error(f"An unexpected error occurred: {e}")
219
+ st.warning('Please enter your puzzle!mathmatical tool', icon='⚠️')
220
+
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ openai
3
+ langchain
4
+ pandas
5
+ openpyxl
6
+ tabulate==0.9.0
7
+ streamlit-option-menu
8
+ pydantic==1.8