ethanrom commited on
Commit
aacc1ec
·
1 Parent(s): 43dadf3

Upload 7 files

Browse files
Files changed (8) hide show
  1. .gitattributes +1 -0
  2. 2023-07-22 19-52-10.mp4 +3 -0
  3. app.py +459 -0
  4. default_text.py +23 -0
  5. generate_plot.py +26 -0
  6. image.jpg +0 -0
  7. markup.py +29 -0
  8. requirements.txt +7 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ 2023-07-22[[:space:]]19-52-10.mp4 filter=lfs diff=lfs merge=lfs -text
2023-07-22 19-52-10.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e95b69b12d405e77be51f9c6a69a1413b5d1913a0a04e78cc66f5e8200191362
3
+ size 1783597
app.py ADDED
@@ -0,0 +1,459 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import plotly.graph_objects as go
3
+ import json
4
+ import os
5
+ import numpy as np
6
+ from streamlit_option_menu import option_menu
7
+ from markup import app_intro, how_use_intro
8
+ from sklearn.linear_model import LinearRegression
9
+ from default_text import default_text4, default_text5
10
+ from generate_plot import generate_plot, set_openai_api_key
11
+
12
+ PASSWORD = 'Ethan101'
13
+
14
+ def authenticate(password):
15
+ return password == PASSWORD
16
+
17
+ def tab1():
18
+ st.header("Economic Simulator and Python Coding Tutor")
19
+ col1, col2 = st.columns([1, 2])
20
+ with col1:
21
+ st.image("image.jpg", use_column_width=True)
22
+ with col2:
23
+ st.markdown(app_intro(), unsafe_allow_html=True)
24
+ st.markdown(how_use_intro(),unsafe_allow_html=True)
25
+
26
+
27
+ github_link = '[<img src="https://badgen.net/badge/icon/github?icon=github&label">](https://github.com/ethanrom)'
28
+ huggingface_link = '[<img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue">](https://huggingface.co/ethanrom)'
29
+
30
+ st.write(github_link + '&nbsp;&nbsp;&nbsp;' + huggingface_link, unsafe_allow_html=True)
31
+
32
+ def simulate_economy(monthly_individual_income, monthly_individual_expense, start_month, start_year, num_months=12):
33
+ income_params = json.loads(monthly_individual_income)
34
+ expense_params = json.loads(monthly_individual_expense)
35
+
36
+ # Simulate economic data
37
+ np.random.seed(42)
38
+ monthly_income = np.random.normal(loc=income_params["mean"], scale=income_params["standarddeviation"], size=num_months)
39
+ monthly_income = np.clip(monthly_income, income_params["min"], income_params["max"])
40
+
41
+ monthly_expense = np.random.normal(loc=expense_params["mean"], scale=expense_params["standarddeviation"], size=num_months)
42
+ monthly_expense = np.clip(monthly_expense, expense_params["min"], expense_params["max"])
43
+
44
+ total_income_per_year = np.sum(monthly_income) * 12
45
+ average_income_per_year = np.mean(monthly_income) * 12
46
+
47
+ families_beyond_means = np.sum(monthly_income < monthly_expense)
48
+ families_paycheck_to_paycheck = np.sum(monthly_income >= monthly_expense)
49
+
50
+ return families_beyond_means, families_paycheck_to_paycheck, average_income_per_year, monthly_income, monthly_expense
51
+
52
+ def plot_line_chart(data, x_label, y_label, title):
53
+ fig = go.Figure()
54
+ fig.add_trace(go.Scatter(x=list(range(len(data))), y=data, mode='lines', name=title))
55
+ fig.update_layout(title=title, xaxis_title=x_label, yaxis_title=y_label)
56
+ return fig
57
+
58
+ def tab2():
59
+
60
+ password_input = st.text_input('Enter Password', type='password')
61
+ if authenticate(password_input):
62
+
63
+ st.header("User Inputs")
64
+ monthly_individual_income = st.text_area("Monthly Individual Income (Python code snippet)", value='''{
65
+ "mean": 4000,
66
+ "min": 1200,
67
+ "max": 15000,
68
+ "standarddeviation": 2000
69
+ }''')
70
+ monthly_individual_expense = st.text_area("Monthly Individual Expense (Python code snippet)", value='''{
71
+ "mean": 4000,
72
+ "min": 1200,
73
+ "max": 15000,
74
+ "standarddeviation": 2000
75
+ }''')
76
+ start_month = st.selectbox("Start Month", ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'])
77
+ start_year = st.number_input("Start Year", min_value=1900, max_value=2100, value=2021)
78
+
79
+ if st.button("Run Simulation"):
80
+ try:
81
+ num_months = 12
82
+ families_beyond_means, families_paycheck_to_paycheck, average_income_per_year, monthly_income, monthly_expense = simulate_economy(monthly_individual_income, monthly_individual_expense, start_month, start_year, num_months)
83
+ st.header("Simulation Results")
84
+ st.write(f"Number of families living beyond their means: {families_beyond_means}")
85
+ st.write(f"Number of families living paycheck to paycheck: {families_paycheck_to_paycheck}")
86
+ st.write(f"Average income per year: ${average_income_per_year:.2f}")
87
+
88
+ st.header("Monthly Income and Expense")
89
+ income_chart = plot_line_chart(monthly_income, "Month", "Income", "Monthly Individual Income")
90
+ st.plotly_chart(income_chart)
91
+
92
+ expense_chart = plot_line_chart(monthly_expense, "Month", "Expense", "Monthly Individual Expense")
93
+ st.plotly_chart(expense_chart)
94
+
95
+ st.header("Code Snippets")
96
+ st.subheader("Calculation of Number of Families living beyond their means")
97
+ st.code("""
98
+ import numpy as np
99
+
100
+ # Assuming monthly_income and monthly_expense are numpy arrays
101
+ families_beyond_means = np.sum(monthly_income < monthly_expense)
102
+ """, language="python")
103
+
104
+ st.subheader("Calculation of Number of Families living paycheck to paycheck")
105
+ st.code("""
106
+ import numpy as np
107
+
108
+ # Assuming monthly_income and monthly_expense are numpy arrays
109
+ families_paycheck_to_paycheck = np.sum(monthly_income >= monthly_expense)
110
+ """, language="python")
111
+
112
+ st.subheader("Calculation of Average income per year")
113
+ st.code(f"""
114
+ # Assuming monthly_income is a numpy array
115
+ average_income_per_year = np.mean(monthly_income) * 12
116
+ """, language="python")
117
+ except Exception as e:
118
+ st.error(f"An error occurred: {e}")
119
+
120
+ else:
121
+ # Password is incorrect, show an error message
122
+ st.error('Invalid password. Access denied.')
123
+
124
+
125
+ def tab3():
126
+ st.header("Python Plotly Coding Tutor")
127
+
128
+ password_input = st.text_input('Enter Password', type='password')
129
+ if authenticate(password_input):
130
+
131
+ # Economy-related example data
132
+ years = np.arange(2010, 2022)
133
+ gdp = [12500, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000]
134
+ unemployment_rate = [8.3, 7.9, 7.2, 6.8, 6.1, 5.6, 5.2, 4.8, 4.3, 4.1, 3.9, 3.7]
135
+
136
+ st.subheader("Example: GDP over the Years")
137
+ st.write("Below is a plot showing the GDP growth over the years.")
138
+
139
+ # Plotting GDP over the years using Plotly
140
+ fig_gdp = go.Figure()
141
+ fig_gdp.add_trace(go.Scatter(x=years, y=gdp, mode='lines+markers', name='GDP'))
142
+ fig_gdp.update_layout(title='GDP Growth Over the Years',
143
+ xaxis_title='Year',
144
+ yaxis_title='GDP (Billion USD)')
145
+
146
+ # Display Python code and explanation
147
+ st.write("Python code for GDP plot:")
148
+ st.code("""
149
+ # Import necessary libraries
150
+ import plotly.graph_objects as go
151
+ import numpy as np
152
+
153
+ # Sample data for years and GDP
154
+ years = np.arange(2010, 2022)
155
+ gdp = [12500, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000]
156
+
157
+ # Create a Plotly figure object
158
+ fig_gdp = go.Figure()
159
+
160
+ # Add a line plot for GDP data
161
+ fig_gdp.add_trace(go.Scatter(x=years, y=gdp, mode='lines+markers', name='GDP'))
162
+
163
+ # Customize the plot layout
164
+ fig_gdp.update_layout(title='GDP Growth Over the Years',
165
+ xaxis_title='Year',
166
+ yaxis_title='GDP (Billion USD)')
167
+
168
+ # Display the plot
169
+ st.plotly_chart(fig_gdp)
170
+ """)
171
+ st.write("This code uses the Plotly library to create an interactive line plot showing the GDP growth over the years. First, we import the necessary libraries, including Plotly and NumPy (for generating sample data). Next, we define the data for the years and the corresponding GDP values. We then create a Plotly figure object (`fig_gdp`) and add a line plot to it using the `go.Scatter` function. The plot is customized with a title and axis labels using the `update_layout` method. Finally, we use `st.plotly_chart` to display the plot in the Streamlit app.")
172
+
173
+ # Display the plot
174
+ st.plotly_chart(fig_gdp)
175
+
176
+ st.subheader("Example: Unemployment Rate over the Years")
177
+ st.write("Below is a plot showing the unemployment rate over the years.")
178
+
179
+ # Plotting unemployment rate over the years using Plotly
180
+ fig_unemployment = go.Figure()
181
+ fig_unemployment.add_trace(go.Scatter(x=years, y=unemployment_rate, mode='lines+markers', name='Unemployment Rate'))
182
+ fig_unemployment.update_layout(title='Unemployment Rate Over the Years',
183
+ xaxis_title='Year',
184
+ yaxis_title='Unemployment Rate (%)')
185
+
186
+ # Display Python code and explanation
187
+ st.write("Python code for Unemployment Rate plot:")
188
+ st.code("""
189
+ # Import necessary libraries
190
+ import plotly.graph_objects as go
191
+ import numpy as np
192
+
193
+ # Sample data for years and unemployment rate
194
+ years = np.arange(2010, 2022)
195
+ unemployment_rate = [8.3, 7.9, 7.2, 6.8, 6.1, 5.6, 5.2, 4.8, 4.3, 4.1, 3.9, 3.7]
196
+
197
+ # Create a Plotly figure object
198
+ fig_unemployment = go.Figure()
199
+
200
+ # Add a line plot for unemployment rate data
201
+ fig_unemployment.add_trace(go.Scatter(x=years, y=unemployment_rate, mode='lines+markers', name='Unemployment Rate'))
202
+
203
+ # Customize the plot layout
204
+ fig_unemployment.update_layout(title='Unemployment Rate Over the Years',
205
+ xaxis_title='Year',
206
+ yaxis_title='Unemployment Rate (%)')
207
+
208
+ # Display the plot
209
+ st.plotly_chart(fig_unemployment)
210
+ """)
211
+ st.write("This code uses the Plotly library to create an interactive line plot showing the unemployment rate over the years. Similar to the previous example, we import the necessary libraries and define the data for the years and the corresponding unemployment rate. We then create a Plotly figure object (`fig_unemployment`) and add a line plot to it using the `go.Scatter` function. The plot is customized with a title and axis labels using the `update_layout` method. Finally, we use `st.plotly_chart` to display the plot in the Streamlit app.")
212
+
213
+ # Display the plot
214
+ st.plotly_chart(fig_unemployment)
215
+
216
+ st.subheader("Try Your Own Plotly Code!")
217
+ st.write("You can type in your Plotly code below and click the 'Run Code' button to see your plot.")
218
+
219
+ # Code input text area
220
+ code_input = st.text_area("Type your Plotly code here:")
221
+
222
+ # Run button
223
+ if st.button("Run Code"):
224
+ try:
225
+ # Execute the user's code
226
+ exec(code_input)
227
+ except Exception as e:
228
+ st.error(f"Error: {e}")
229
+
230
+ else:
231
+ # Password is incorrect, show an error message
232
+ st.error('Invalid password. Access denied.')
233
+
234
+
235
+ def tab4():
236
+ st.header("Customizable Plot with Plotly")
237
+
238
+ password_input = st.text_input('Enter Password', type='password')
239
+ if authenticate(password_input):
240
+
241
+ example_x_values = [2010, 2011, 2012, 2013, 2014, 2015]
242
+ example_y_values = [12500, 13000, 14000, 15000, 16000, 17000]
243
+
244
+ st.subheader("Customize Your Plot:")
245
+ col1, col2 = st.columns([1, 2])
246
+ with col1:
247
+ x_axis = st.text_input("Enter X-axis title:", "Years")
248
+ y_axis = st.text_input("Enter Y-axis title:", "GDP")
249
+ chart_type = st.selectbox("Choose Chart Type:", ["Scatter", "Line", "Bar"])
250
+ line_mode = st.selectbox("Choose Line Mode:", ["lines", "lines+markers", "markers"])
251
+ plot_color = st.color_picker("Choose Plot Color:", "#1f77b4")
252
+ with col2:
253
+ x_values = st.text_area("Enter X-axis values (comma-separated):", ", ".join(map(str, example_x_values)))
254
+ y_values = st.text_area("Enter Y-axis values (comma-separated):", ", ".join(map(str, example_y_values)))
255
+
256
+ try:
257
+ x_values = [float(x.strip()) for x in x_values.split(",")]
258
+ y_values = [float(y.strip()) for y in y_values.split(",")]
259
+ except ValueError:
260
+ st.error("Invalid input for x or y axis. Please enter valid numeric values.")
261
+
262
+ fig_custom = go.Figure()
263
+
264
+ if chart_type == "Scatter":
265
+ fig_custom.add_trace(go.Scatter(x=x_values, y=y_values, mode=line_mode, name=y_axis, marker_color=plot_color))
266
+ elif chart_type == "Line":
267
+ fig_custom.add_trace(go.Line(x=x_values, y=y_values, mode=line_mode, name=y_axis, line_color=plot_color))
268
+ elif chart_type == "Bar":
269
+ fig_custom.add_trace(go.Bar(x=x_values, y=y_values, name=y_axis, marker_color=plot_color))
270
+
271
+ fig_custom.update_layout(title=f"{y_axis} vs. {x_axis}",
272
+ xaxis_title=x_axis,
273
+ yaxis_title=y_axis)
274
+
275
+ st.subheader("Customized Plot:")
276
+ st.plotly_chart(fig_custom)
277
+
278
+ st.subheader("Python Code to Create the Customized Plot:")
279
+ code = f"""
280
+ import plotly.graph_objects as go
281
+
282
+ x_values = {x_values}
283
+ y_values = {y_values}
284
+
285
+ fig_custom = go.Figure()
286
+ """
287
+
288
+ if chart_type == "Scatter":
289
+ code += f"""
290
+ fig_custom.add_trace(go.Scatter(x=x_values, y=y_values, mode='{line_mode}', name='{y_axis}', marker_color='{plot_color}'))
291
+ """
292
+ elif chart_type == "Line":
293
+ code += f"""
294
+ fig_custom.add_trace(go.Line(x=x_values, y=y_values, mode='{line_mode}', name='{y_axis}', line_color='{plot_color}'))
295
+ """
296
+ elif chart_type == "Bar":
297
+ code += f"""
298
+ fig_custom.add_trace(go.Bar(x=x_values, y=y_values, name='{y_axis}', marker_color='{plot_color}'))
299
+ """
300
+
301
+ code += f"""
302
+ fig_custom.update_layout(title='{y_axis} vs. {x_axis}',
303
+ xaxis_title='{x_axis}',
304
+ yaxis_title='{y_axis}')
305
+ """
306
+
307
+ st.code(code)
308
+
309
+ else:
310
+ # Password is incorrect, show an error message
311
+ st.error('Invalid password. Access denied.')
312
+
313
+ def tab5():
314
+ st.header("Building Predictive Models with Plotly")
315
+
316
+ password_input = st.text_input('Enter Password', type='password')
317
+ if authenticate(password_input):
318
+
319
+ np.random.seed(42)
320
+ x = np.arange(1, 11)
321
+ y = 2 * x + 3 + np.random.randn(10)
322
+
323
+ st.subheader("Linear Regression Example:")
324
+ st.write("Let's consider a simple linear regression example using the following data:")
325
+
326
+ col1, col2 = st.columns(2)
327
+ with col1:
328
+ st.write("X (Independent Variable):", x)
329
+ with col2:
330
+ st.write("Y (Dependent Variable):", y)
331
+
332
+ fig_data = go.Figure()
333
+ fig_data.add_trace(go.Scatter(x=x, y=y, mode='markers', name='Data Points'))
334
+ fig_data.update_layout(title='Data Points for Linear Regression',
335
+ xaxis_title='X (Independent Variable)',
336
+ yaxis_title='Y (Dependent Variable)')
337
+
338
+ with col1:
339
+ st.plotly_chart(fig_data)
340
+
341
+ model = LinearRegression()
342
+ x_reshaped = x.reshape(-1, 1)
343
+ model.fit(x_reshaped, y)
344
+
345
+ st.subheader("Interactivity and Model Adjustment:")
346
+ st.write("You can interact with the chart by adjusting the values of the slope and intercept.")
347
+ st.write("Changing these parameters will modify the regression line and the predictions.")
348
+ st.write("Feel free to experiment and observe how the line fits the data differently.")
349
+
350
+ # Sliders for slope and intercept
351
+ slope_slider = st.slider("Slope (Coefficient)", min_value=-10.0, max_value=10.0, value=2.0, step=0.1)
352
+ intercept_slider = st.slider("Intercept", min_value=-10.0, max_value=10.0, value=3.0, step=0.1)
353
+
354
+ # Calculate predictions based on user-adjusted slope and intercept
355
+ y_pred_adjusted = slope_slider * x + intercept_slider
356
+
357
+ fig_regression = go.Figure()
358
+ fig_regression.add_trace(go.Scatter(x=x, y=y, mode='markers', name='Data Points'))
359
+ fig_regression.add_trace(go.Scatter(x=x, y=y_pred_adjusted, mode='lines', name='Regression Line', line=dict(color='red')))
360
+ fig_regression.update_layout(title='Linear Regression',
361
+ xaxis_title='X (Independent Variable)',
362
+ yaxis_title='Y (Dependent Variable)')
363
+
364
+ st.plotly_chart(fig_regression)
365
+
366
+ st.subheader("Interpreting Model Coefficients:")
367
+ st.write("The slope of the regression line represents how much Y changes for a one-unit increase in X.")
368
+ st.write("The intercept is the value of Y when X is 0. In our example, the intercept is 3.")
369
+ st.write("For each unit increase in X, Y increases by the slope you adjusted using the slider.")
370
+
371
+ st.subheader("Python Code for Linear Regression:")
372
+ code = """
373
+ import numpy as np
374
+ from sklearn.linear_model import LinearRegression
375
+
376
+ # Sample data for linear regression example
377
+ x = np.arange(1, 11)
378
+ y = 2 * x + 3 + np.random.randn(10)
379
+
380
+ # Perform linear regression and get the predicted values
381
+ model = LinearRegression()
382
+ x_reshaped = x.reshape(-1, 1)
383
+ model.fit(x_reshaped, y)
384
+ slope = model.coef_[0]
385
+ intercept = model.intercept_
386
+
387
+ # Display the coefficients
388
+ print("Slope (Coefficient):", slope)
389
+ print("Intercept:", intercept)
390
+ """
391
+ st.code(code)
392
+ else:
393
+ # Password is incorrect, show an error message
394
+ st.error('Invalid password. Access denied.')
395
+
396
+
397
+ def tab6():
398
+ st.header("Auto Plot Generator")
399
+ st.markdown("Auto Generate code and plot for a given question")
400
+ password_input = st.text_input('Enter Password', type='password')
401
+ if authenticate(password_input):
402
+
403
+ openai_api_key = st.text_input("Enter your OpenAI API key:", type='password')
404
+
405
+ # Add the video display
406
+ video_file = "2023-07-22 19-52-10.mp4"
407
+ if os.path.exists(video_file):
408
+ st.video(video_file)
409
+ else:
410
+ st.warning("Video file not found.")
411
+
412
+ main_question = st.text_area("Enter Information here:", height=400, value=default_text4)
413
+ sub_question = st.text_area("Enter question here:", value=default_text5)
414
+
415
+ result = None
416
+
417
+ if st.button("Generate Code"):
418
+ if openai_api_key:
419
+ set_openai_api_key(openai_api_key)
420
+ with st.spinner('Thinking...'):
421
+ result = generate_plot(main_question, sub_question)
422
+ st.code(result)
423
+ st.session_state.generated_code = result
424
+ else:
425
+ st.warning("Please enter your OpenAI API key.")
426
+
427
+ if st.button("Show Plot"):
428
+ if 'generated_code' in st.session_state:
429
+ with st.spinner('Generating Plot...'):
430
+ exec(st.session_state.generated_code)
431
+ else:
432
+ st.warning("Please generate the code first.")
433
+
434
+ else:
435
+ # Password is incorrect, show an error message
436
+ st.error('Invalid password. Access denied.')
437
+
438
+ def main():
439
+ st.set_page_config(page_title="Economic Simulator and Python Coding Tutor", page_icon=":memo:", layout="wide")
440
+ tabs = ["Intro", "Simulate", "Learn about plotly usage", "Building custom plots", "Building Predictive Models", "AI Plot Generation"]
441
+
442
+ with st.sidebar:
443
+
444
+ current_tab = option_menu("Select a Tab", tabs, menu_icon="cast")
445
+
446
+ tab_functions = {
447
+ "Intro": tab1,
448
+ "Simulate": tab2,
449
+ "Learn about plotly usage": tab3,
450
+ "Building custom plots": tab4,
451
+ "Building Predictive Models": tab5,
452
+ "AI Plot Generation": tab6,
453
+ }
454
+
455
+ if current_tab in tab_functions:
456
+ tab_functions[current_tab]()
457
+
458
+ if __name__ == "__main__":
459
+ main()
default_text.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ default_text4 = """ The dataset contains the following columns:
2
+
3
+ "Month": The month of the sales data (e.g., January, February, March).
4
+ "Sales": The total sales amount (in dollars) for each month.
5
+
6
+ Here are the first few rows of the dataset:
7
+ Month Sales
8
+ January 1500
9
+ February 1800
10
+ March 2200
11
+ April 1900
12
+ May 2500
13
+ June 2800
14
+ July 3000
15
+ August 3200
16
+ September 2900
17
+ October 2700
18
+ November 2300
19
+ December 3500
20
+
21
+ """
22
+
23
+ default_text5 = """What is the overall trend in monthly sales for the past year?"""
generate_plot.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain import PromptTemplate, LLMChain
2
+ from langchain.llms import OpenAI
3
+ import openai
4
+ import os
5
+
6
+
7
+
8
+ template = """You are given following information and a question. Generate a python code with plotly to find the answer. Provide Text as comments only in code.
9
+
10
+ Information:
11
+ {main_question}
12
+ =============
13
+ Question:
14
+ {sub_question}
15
+ Answer:"""
16
+
17
+ prompt = PromptTemplate(template=template, input_variables=["main_question", "sub_question"])
18
+
19
+ def set_openai_api_key(api_key):
20
+ openai.api_key = api_key
21
+
22
+ def generate_plot(main_question, sub_question):
23
+ llm = OpenAI(temperature=0)
24
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
25
+ response = llm_chain.run(main_question=main_question, sub_question=sub_question)
26
+ return response
image.jpg ADDED
markup.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def app_intro():
2
+ return """
3
+ <div style='text-align: left;'>
4
+ <h2 style='text-align: center;'>Economic Simulator and Python Coding Tutor</h2>
5
+ <h3 style='text-align: center;'>Introduction</h3>
6
+
7
+ <p>This app allows you to run basic economic simulations with values plugged in as Python code snippets.</p>
8
+
9
+ <h4>Information:</h4>
10
+ <ul>
11
+ <li><b>Try different simulations:</b> In this demo, you can easily try different simulations by modifying the Python code snippets for monthly individual income and expense.</li>
12
+ <li><b>Calculate Results:</b> You can calculate the number of families living beyond their means, the number of families living paycheck to paycheck, and the average income per year based on the provided Python code snippets.</li>
13
+ </ul>
14
+ </div>
15
+ """
16
+
17
+ def how_use_intro():
18
+ return """
19
+ <div style='text-align: left;'>
20
+ <h3 style='text-align: center;'>About this Demo</h3>
21
+ <br>
22
+ <h4>How to Use:</h4>
23
+ <ul>
24
+ <li><b>Testing:</b> To run a simulation, provide the Python code snippets for monthly individual income and expense in the text areas. Select the start month and year, and click the "Run Simulation" button. The app will display the simulation results in charts and provide code snippets for the calculations.</li>
25
+ <li><b>Reverse Simulation:</b> You can perform a reverse simulation by checking the "Perform Reverse Simulation" box. This will allow you to input the desired number of families living beyond their means, number of families living paycheck to paycheck, and average income per year. The app will estimate the corresponding Python code snippets for monthly individual income and expense based on the provided results.</li>
26
+ </ul>
27
+ <br>
28
+ </div>
29
+ """
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ plotly
2
+ numpy
3
+ scikit-learn
4
+ streamlit_option_menu
5
+ pandas
6
+ langchain
7
+ openai