baileydiaz commited on
Commit
1e4b03e
1 Parent(s): b5ecec2

here we go!

Browse files
Files changed (2) hide show
  1. requirements.txt +3 -1
  2. streamlit.py +26 -95
requirements.txt CHANGED
@@ -4,4 +4,6 @@ pandas
4
  streamlit
5
  scikit-learn
6
  numpy
7
- plotly
 
 
 
4
  streamlit
5
  scikit-learn
6
  numpy
7
+ plotly
8
+ streamlit-drawable-canvas
9
+ pillow
streamlit.py CHANGED
@@ -1,96 +1,27 @@
1
- # %%
2
- # packages
3
  import streamlit as st
4
- import polars as pl
5
- import plotly.express as px
6
- import plotly.io as pio
7
- pio.templates.default = "simple_white"
8
-
9
- st.set_page_config(layout="wide")
10
- # %%
11
- # Data
12
-
13
- dat = pl.read_csv("dat_munged.csv")
14
- info = pl.read_csv("Metadata_Indicator_API_Download_DS2_en_csv_v2_5657328.csv").rename({"INDICATOR_CODE":"Indicator Code", "INDICATOR_NAME":"Indicator Name"})
15
- dat_vars = pl.read_csv("dat_vars.csv")
16
-
17
- # %%
18
- # Example Chart
19
- # drop_country = ["ZAF"]
20
- # indicator_code = "NY.GDP.PCAP.PP.KD"
21
- list_name = dat_vars.select("Indicator Name").to_series().to_list()
22
- list_code = dat_vars.select("Indicator Code").to_series().to_list()
23
- list_country_code = ["ZAF", "ZWE", "KEN", "NGA", "GHA", "COD"]
24
- list_country_name = ["South Africa", "Zimbabwe", "Kenya", "Nigeria", "Ghana", "Congo, Dem. Rep."]
25
-
26
-
27
- drop_country = st.sidebar.multiselect("Remove Country (Country Code)", list_country_code)
28
-
29
- checked_var = st.sidebar.checkbox("Use Variable Name")
30
-
31
-
32
- if checked_var:
33
- indicator_name = st.sidebar.selectbox("Select your variable", list_name)
34
- indicator_code = dat_vars.filter(pl.col("Indicator Name") == indicator_name).select("Indicator Code").to_series()[0]
35
- else:
36
- indicator_code = st.sidebar.selectbox("Select your variable", list_code)
37
- indicator_name = dat_vars.filter(pl.col("Indicator Code") == indicator_code).select("Indicator Name").to_series()[0]
38
-
39
- title_text = indicator_name
40
- subtitle_text = info.filter(pl.col("Indicator Code") == indicator_code).select("SOURCE_NOTE").to_series()[0]
41
-
42
- y_axis_title = indicator_name[indicator_name.find("(")+1:indicator_name.find(")")]
43
-
44
- use_dat = dat.filter((pl.col("Indicator Code").is_in([str(indicator_code)])) & (~pl.col("Country Code").is_in(drop_country)) & (pl.col("value").is_not_null()))
45
-
46
- sp = px.line(use_dat.to_pandas(),
47
- x="year", y="value", color="Country Name", markers=True,
48
- labels = {"year":"Year", "value":y_axis_title},
49
- title = title_text)
50
-
51
- st.markdown("## Country performance over time")
52
-
53
- st.markdown("_You can read about streamlit [here](slides.html)_")
54
-
55
- st.markdown("__" + title_text + "__")
56
-
57
- st.markdown(subtitle_text)
58
-
59
- st.markdown("### Chart")
60
- st.markdown("_Use the expand arrows visible when you hover over the upper right corner of the chart to see it in full screen._")
61
-
62
- sp
63
-
64
- st.markdown("### Table: " + title_text)
65
-
66
- display_dat = use_dat.select("Country Code", "Indicator Name", "year", "value")
67
-
68
- st.dataframe(
69
- display_dat\
70
- .pivot(index="year", on="Country Code", values="value", aggregate_function="first")\
71
- .sort(pl.col("year"),descending=True), hide_index=True,
72
- use_container_width=True,
73
- column_config={
74
- "value": y_axis_title,
75
- "year": st.column_config.NumberColumn(
76
- "Year",
77
- help="Year of data",
78
- format="%.0f"
79
- )})
80
-
81
-
82
- def convert_df(df):
83
- return df.write_csv().encode('utf-8')
84
-
85
- csv = convert_df(display_dat)
86
-
87
- st.download_button("Download Data", data = csv, file_name = "data.csv", mime="text/csv")
88
-
89
- st.markdown("## My presentation")
90
-
91
- # Read file and keep in variable
92
- with open('slides.html','r') as f:
93
- html_data = f.read()
94
-
95
- ## Show in webpage
96
- st.components.v1.html(html_data,height=1500)
 
 
 
1
  import streamlit as st
2
+ from streamlit_drawable_canvas import st_canvas
3
+ from PIL import Image
4
+
5
+ # Create a camera input widget
6
+ picture = st.camera_input("Take a picture")
7
+
8
+ if picture:
9
+ # Convert the picture to an Image object
10
+ img = Image.open(picture)
11
+
12
+ # Display the drawable canvas with the image
13
+ canvas_result = st_canvas(
14
+ fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
15
+ stroke_width=2,
16
+ stroke_color="black",
17
+ background_image=img,
18
+ update_streamlit=True,
19
+ height=img.height,
20
+ width=img.width,
21
+ drawing_mode="freedraw",
22
+ key="canvas",
23
+ )
24
+
25
+ # Display the resulting image with drawings
26
+ if canvas_result.image_data is not None:
27
+ st.image(canvas_result.image_data)